pidgin/gtkimhtml.c

Sun, 05 Dec 2010 08:14:52 +0000

author
Elliott Sales de Andrade <qulogic@pidgin.im>
date
Sun, 05 Dec 2010 08:14:52 +0000
branch
cpw.qulogic.gtk3
changeset 32413
00ad036bdf3d
parent 32412
f718420c4932
child 32414
8c5d1edf9da2
permissions
-rw-r--r--

Fix some indenting.

1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
1 /*
10297
b36800725b7a [gaim-migrate @ 11480]
Evan Schoenberg <evands@pidgin.im>
parents: 10243
diff changeset
2 * @file gtkimhtml.c GTK+ IMHtml
16254
eeb2bba4dc94 Rename the Doxygen group from gtkui to pidgin.
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
3 * @ingroup pidgin
20330
650a7af9c238 remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
4 */
650a7af9c238 remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
5
650a7af9c238 remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
6 /* pidgin
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
7 *
15931
716b5fac1895 Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
8 * Pidgin is the legal property of its developers, whose names are too numerous
8046
c581b20a47d6 [gaim-migrate @ 8730]
Sean Egan <seanegan@pidgin.im>
parents: 8026
diff changeset
9 * to list here. Please refer to the COPYRIGHT file distributed with this
c581b20a47d6 [gaim-migrate @ 8730]
Sean Egan <seanegan@pidgin.im>
parents: 8026
diff changeset
10 * source distribution.
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
11 *
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
12 * This program is free software; you can redistribute it and/or modify
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
13 * under the terms of the GNU General Public License as published by
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
14 * the Free Software Foundation; either version 2 of the License, or
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
15 * (at your option) any later version.
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
16 *
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
17 * This program is distributed in the hope that it will be useful,
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
20 * GNU General Public License for more details.
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
21 *
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
22 * You should have received a copy of the GNU General Public License
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
23 * along with this program; if not, write to the Free Software
19859
71d37b57eff2 The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19746
diff changeset
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
25 *
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
26 */
24569
5dbd0617a27d Build everything with the *_DISABLE_DEPRECATED flags set. This allows us
Richard Laager <rlaager@pidgin.im>
parents: 24544
diff changeset
27 #define _PIDGIN_GTKIMHTML_C_
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
28
2541
0afd3aaba327 [gaim-migrate @ 2554]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2365
diff changeset
29 #ifdef HAVE_CONFIG_H
0afd3aaba327 [gaim-migrate @ 2554]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2365
diff changeset
30 #include <config.h>
0afd3aaba327 [gaim-migrate @ 2554]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2365
diff changeset
31 #endif
18119
699d876e3db0 Include pidgin.h to make this compile.
Richard Laager <rlaager@pidgin.im>
parents: 18108
diff changeset
32
18633
34ba43198355 Fix the win32 build. Thanks to Etan and Lee Roach. Fixes #1929.
Daniel Atallah <datallah@pidgin.im>
parents: 18552
diff changeset
33 #include "internal.h"
18119
699d876e3db0 Include pidgin.h to make this compile.
Richard Laager <rlaager@pidgin.im>
parents: 18108
diff changeset
34 #include "pidgin.h"
21777
0662651f6902 Kevin says we're ok defaulting persistent IMs on
Sean Egan <seanegan@pidgin.im>
parents: 21765
diff changeset
35 #include "pidginstock.h"
23304
3aba02105818 Modified patch from malu to "Add context menu alternative to add received
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23302
diff changeset
36 #include "gtkutils.h"
3aba02105818 Modified patch from malu to "Add context menu alternative to add received
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23302
diff changeset
37 #include "smiley.h"
3aba02105818 Modified patch from malu to "Add context menu alternative to add received
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23302
diff changeset
38 #include "imgstore.h"
18119
699d876e3db0 Include pidgin.h to make this compile.
Richard Laager <rlaager@pidgin.im>
parents: 18108
diff changeset
39
8526
cea38c0015e6 [gaim-migrate @ 9265]
Daniel Atallah <datallah@pidgin.im>
parents: 8519
diff changeset
40 #include "debug.h"
8091
e2ffba819297 [gaim-migrate @ 8790]
Sean Egan <seanegan@pidgin.im>
parents: 8061
diff changeset
41 #include "util.h"
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
42 #include "gtkimhtml.h"
23304
3aba02105818 Modified patch from malu to "Add context menu alternative to add received
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23302
diff changeset
43 #include "gtksmiley.h"
7358
129ed09d791d [gaim-migrate @ 7951]
Sean Egan <seanegan@pidgin.im>
parents: 7354
diff changeset
44 #include "gtksourceiter.h"
17880
5e73968467e0 Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents: 17288
diff changeset
45 #include "gtksourceundomanager.h"
5e73968467e0 Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents: 17288
diff changeset
46 #include "gtksourceview-marshal.h"
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
47 #include <gtk/gtk.h>
26727
b8885bab55ab More updates for GTK+ 3.0. This only fixes the single-includes. Fixing all
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26655
diff changeset
48 #include <glib.h>
4046
3b7f7799fe5b [gaim-migrate @ 4254]
Sean Egan <seanegan@pidgin.im>
parents: 4041
diff changeset
49 #include <gdk/gdkkeysyms.h>
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
50 #include <string.h>
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
51 #include <ctype.h>
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
52 #include <stdio.h>
4629
7ac4830de853 [gaim-migrate @ 4920]
Mark Doliner <markdoliner@pidgin.im>
parents: 4612
diff changeset
53 #include <stdlib.h>
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
54 #include <math.h>
2541
0afd3aaba327 [gaim-migrate @ 2554]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2365
diff changeset
55 #ifdef HAVE_LANGINFO_CODESET
0afd3aaba327 [gaim-migrate @ 2554]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2365
diff changeset
56 #include <langinfo.h>
0afd3aaba327 [gaim-migrate @ 2554]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2365
diff changeset
57 #include <locale.h>
0afd3aaba327 [gaim-migrate @ 2554]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2365
diff changeset
58 #endif
8692
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
59 #ifdef _WIN32
10901
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
60 #include <gdk/gdkwin32.h>
8692
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
61 #include <windows.h>
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
62 #endif
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
63
4735
ac5f2489f6ee [gaim-migrate @ 5050]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4635
diff changeset
64 #include <pango/pango-font.h>
ac5f2489f6ee [gaim-migrate @ 5050]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4635
diff changeset
65
ac5f2489f6ee [gaim-migrate @ 5050]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4635
diff changeset
66 #define TOOLTIP_TIMEOUT 500
ac5f2489f6ee [gaim-migrate @ 5050]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4635
diff changeset
67
10100
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
68 static GtkTextViewClass *parent_class = NULL;
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
69
11224
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
70 struct scalable_data {
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
71 GtkIMHtmlScalable *scalable;
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
72 GtkTextMark *mark;
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
73 };
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
74
27123
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
75 typedef struct {
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
76 GtkIMHtmlScalable *image;
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
77 gpointer data;
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
78 gsize datasize;
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
79 } GtkIMHtmlImageSave;
11224
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
80
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
81 struct im_image_data {
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
82 int id;
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
83 GtkTextMark *mark;
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
84 };
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
85
24698
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
86 struct _GtkIMHtmlLink
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
87 {
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
88 GtkIMHtml *imhtml;
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
89 gchar *url;
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
90 GtkTextTag *tag;
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
91 };
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
92
24674
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
93 typedef struct _GtkIMHtmlProtocol
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
94 {
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
95 char *name;
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
96 int length;
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
97
24698
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
98 gboolean (*activate)(GtkIMHtml *imhtml, GtkIMHtmlLink *link);
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
99 gboolean (*context_menu)(GtkIMHtml *imhtml, GtkIMHtmlLink *link, GtkWidget *menu);
24674
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
100 } GtkIMHtmlProtocol;
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
101
9300
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
102 static gboolean
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
103 gtk_text_view_drag_motion (GtkWidget *widget,
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
104 GdkDragContext *context,
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
105 gint x,
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
106 gint y,
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
107 guint time);
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
108
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
109 static void preinsert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
110 static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml);
12673
4c8a20955e0b [gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12672
diff changeset
111 static void delete_cb(GtkTextBuffer *buffer, GtkTextIter *iter, GtkTextIter *end, GtkIMHtml *imhtml);
10169
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
112 static void insert_ca_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextChildAnchor *arg2, gpointer user_data);
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
113 static void gtk_imhtml_apply_tags_on_insert(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end);
8698
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
114 void gtk_imhtml_close_tags(GtkIMHtml *imhtml, GtkTextIter *iter);
9300
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
115 static void gtk_imhtml_link_drop_cb(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer user_data);
8091
e2ffba819297 [gaim-migrate @ 8790]
Sean Egan <seanegan@pidgin.im>
parents: 8061
diff changeset
116 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
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
117 static void mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, GtkIMHtml *imhtml);
8931
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
118 static void hijack_menu_cb(GtkIMHtml *imhtml, GtkMenu *menu, gpointer data);
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
119 static void paste_received_cb (GtkClipboard *clipboard, GtkSelectionData *selection_data, gpointer data);
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
120 static void paste_plaintext_received_cb (GtkClipboard *clipboard, const gchar *text, gpointer data);
10901
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
121 static void imhtml_paste_insert(GtkIMHtml *imhtml, const char *text, gboolean plaintext);
11267
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
122 static void imhtml_toggle_bold(GtkIMHtml *imhtml);
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
123 static void imhtml_toggle_italic(GtkIMHtml *imhtml);
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
124 static void imhtml_toggle_strike(GtkIMHtml *imhtml);
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
125 static void imhtml_toggle_underline(GtkIMHtml *imhtml);
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
126 static void imhtml_font_grow(GtkIMHtml *imhtml);
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
127 static void imhtml_font_shrink(GtkIMHtml *imhtml);
12672
673e2a1d2954 [gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12635
diff changeset
128 static void imhtml_clear_formatting(GtkIMHtml *imhtml);
24674
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
129 static int gtk_imhtml_is_protocol(const char *text);
24698
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
130 static void gtk_imhtml_activate_tag(GtkIMHtml *imhtml, GtkTextTag *tag);
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
131 static void gtk_imhtml_link_destroy(GtkIMHtmlLink *link);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
132
10899
87d9aec5b72d [gaim-migrate @ 12619]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10871
diff changeset
133 /* POINT_SIZE converts from AIM font sizes to a point size scale factor. */
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
134 #define MAX_FONT_SIZE 7
10900
cc19dfd83910 [gaim-migrate @ 12621]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10899
diff changeset
135 #define POINT_SIZE(x) (_point_sizes [MIN ((x > 0 ? x : 1), MAX_FONT_SIZE) - 1])
21091
07fe1a99c47b Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@pidgin.im>
parents: 21085
diff changeset
136 static const gdouble _point_sizes [] = { .85, .95, 1, 1.2, 1.44, 1.728, 2.0736};
2349
9832b57ded64 [gaim-migrate @ 2362]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2348
diff changeset
137
10184
543c9a84ce16 [gaim-migrate @ 11299]
Mark Doliner <markdoliner@pidgin.im>
parents: 10169
diff changeset
138 enum {
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
139 TARGET_HTML,
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
140 TARGET_UTF8_STRING,
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
141 TARGET_COMPOUND_TEXT,
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
142 TARGET_STRING,
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
143 TARGET_TEXT
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
144 };
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
145
8091
e2ffba819297 [gaim-migrate @ 8790]
Sean Egan <seanegan@pidgin.im>
parents: 8061
diff changeset
146 enum {
8420
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
147 URL_CLICKED,
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
148 BUTTONS_UPDATE,
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
149 TOGGLE_FORMAT,
8427
b99f5085af0a [gaim-migrate @ 9157]
Sean Egan <seanegan@pidgin.im>
parents: 8420
diff changeset
150 CLEAR_FORMAT,
8506
76ce3a78b130 [gaim-migrate @ 9242]
Gary Kramlich <grim@pidgin.im>
parents: 8505
diff changeset
151 UPDATE_FORMAT,
10108
0897c42d6cb9 [gaim-migrate @ 11141]
Sean Egan <seanegan@pidgin.im>
parents: 10100
diff changeset
152 MESSAGE_SEND,
17880
5e73968467e0 Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents: 17288
diff changeset
153 UNDO,
5e73968467e0 Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents: 17288
diff changeset
154 REDO,
29909
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
155 PASTE,
8420
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
156 LAST_SIGNAL
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
157 };
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
158 static guint signals [LAST_SIGNAL] = { 0 };
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
159
17546
51b1c1e2c3fe Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents: 17406
diff changeset
160 static char *html_clipboard = NULL;
51b1c1e2c3fe Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents: 17406
diff changeset
161 static char *text_clipboard = NULL;
21085
dff5e0bfb8f5 Don't assign ownership of the CLIPBOARD to the IMHtml - it doesn't really own the data and then we don't have problems of overwriting what others put in the clipboard. Fixes #3616.
Daniel Atallah <datallah@pidgin.im>
parents: 21076
diff changeset
162 static GtkClipboard *clipboard_selection = NULL;
17546
51b1c1e2c3fe Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents: 17406
diff changeset
163
21091
07fe1a99c47b Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@pidgin.im>
parents: 21085
diff changeset
164 static const GtkTargetEntry selection_targets[] = {
15111
e427dd6f3b7e [gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents: 15093
diff changeset
165 #ifndef _WIN32
8566
d174105077ff [gaim-migrate @ 9313]
Sean Egan <seanegan@pidgin.im>
parents: 8548
diff changeset
166 { "text/html", 0, TARGET_HTML },
15111
e427dd6f3b7e [gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents: 15093
diff changeset
167 #else
e427dd6f3b7e [gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents: 15093
diff changeset
168 { "HTML Format", 0, TARGET_HTML },
e427dd6f3b7e [gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents: 15093
diff changeset
169 #endif
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
170 { "UTF8_STRING", 0, TARGET_UTF8_STRING },
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
171 { "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT },
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
172 { "STRING", 0, TARGET_STRING },
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
173 { "TEXT", 0, TARGET_TEXT}};
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
174
21091
07fe1a99c47b Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@pidgin.im>
parents: 21085
diff changeset
175 static const GtkTargetEntry link_drag_drop_targets[] = {
10145
f1405f65ff41 [gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10110
diff changeset
176 GTK_IMHTML_DND_TARGETS
f1405f65ff41 [gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10110
diff changeset
177 };
8091
e2ffba819297 [gaim-migrate @ 8790]
Sean Egan <seanegan@pidgin.im>
parents: 8061
diff changeset
178
8692
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
179 #ifdef _WIN32
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
180 static gchar *
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
181 clipboard_win32_to_html(char *clipboard) {
9465
652dcd45db7d [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
182 const char *header;
8693
e4579335a6f6 [gaim-migrate @ 9446]
Kevin Stange <kstange@pidgin.im>
parents: 8692
diff changeset
183 const char *begin, *end;
10016
18418b9fa749 [gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents: 10013
diff changeset
184 gint start = 0;
18418b9fa749 [gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents: 10013
diff changeset
185 gint finish = 0;
8692
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
186 gchar *html;
10016
18418b9fa749 [gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents: 10013
diff changeset
187 gchar **split;
18418b9fa749 [gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents: 10013
diff changeset
188 int clipboard_length = 0;
9465
652dcd45db7d [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
189
652dcd45db7d [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
190 #if 0 /* Debugging for Windows clipboard */
9467
591db7463935 [gaim-migrate @ 10292]
Kevin Stange <kstange@pidgin.im>
parents: 9465
diff changeset
191 FILE *fd;
591db7463935 [gaim-migrate @ 10292]
Kevin Stange <kstange@pidgin.im>
parents: 9465
diff changeset
192
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15865
diff changeset
193 purple_debug_info("imhtml clipboard", "from clipboard: %s\n", clipboard);
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15865
diff changeset
194
29855
234f74a60570 I think this works around the problem with the Win32 Clipboard and GTK+ 2.16.
Daniel Atallah <datallah@pidgin.im>
parents: 29724
diff changeset
195 fd = g_fopen("c:\\purplecb.txt", "wb");
9465
652dcd45db7d [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
196 fprintf(fd, "%s", clipboard);
652dcd45db7d [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
197 fclose(fd);
652dcd45db7d [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
198 #endif
652dcd45db7d [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
199
10016
18418b9fa749 [gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents: 10013
diff changeset
200 clipboard_length = strlen(clipboard);
18418b9fa749 [gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents: 10013
diff changeset
201
18418b9fa749 [gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents: 10013
diff changeset
202 if (!(header = strstr(clipboard, "StartFragment:")) || (header - clipboard) >= clipboard_length)
9465
652dcd45db7d [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
203 return NULL;
652dcd45db7d [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
204 sscanf(header, "StartFragment:%d", &start);
652dcd45db7d [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
205
10016
18418b9fa749 [gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents: 10013
diff changeset
206 if (!(header = strstr(clipboard, "EndFragment:")) || (header - clipboard) >= clipboard_length)
18418b9fa749 [gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents: 10013
diff changeset
207 return NULL;
9465
652dcd45db7d [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
208 sscanf(header, "EndFragment:%d", &finish);
652dcd45db7d [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
209
10016
18418b9fa749 [gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents: 10013
diff changeset
210 if (finish > clipboard_length)
18418b9fa749 [gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents: 10013
diff changeset
211 finish = clipboard_length;
18418b9fa749 [gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents: 10013
diff changeset
212
18418b9fa749 [gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents: 10013
diff changeset
213 if (start > finish)
18418b9fa749 [gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents: 10013
diff changeset
214 start = finish;
18418b9fa749 [gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents: 10013
diff changeset
215
9465
652dcd45db7d [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
216 begin = clipboard + start;
652dcd45db7d [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
217
10016
18418b9fa749 [gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents: 10013
diff changeset
218 end = clipboard + finish;
18418b9fa749 [gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents: 10013
diff changeset
219
18418b9fa749 [gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents: 10013
diff changeset
220 html = g_strndup(begin, end - begin);
18418b9fa749 [gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents: 10013
diff changeset
221
18418b9fa749 [gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents: 10013
diff changeset
222 /* any newlines in the string will now be \r\n, so we need to strip out the \r */
18418b9fa749 [gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents: 10013
diff changeset
223 split = g_strsplit(html, "\r\n", 0);
18418b9fa749 [gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents: 10013
diff changeset
224 g_free(html);
18418b9fa749 [gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents: 10013
diff changeset
225 html = g_strjoinv("\n", split);
18418b9fa749 [gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents: 10013
diff changeset
226 g_strfreev(split);
18418b9fa749 [gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents: 10013
diff changeset
227
9465
652dcd45db7d [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
228 #if 0 /* Debugging for Windows clipboard */
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15865
diff changeset
229 purple_debug_info("imhtml clipboard", "HTML fragment: '%s'\n", html);
9465
652dcd45db7d [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
230 #endif
652dcd45db7d [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
231
8707
024f6481c017 [gaim-migrate @ 9460]
Kevin Stange <kstange@pidgin.im>
parents: 8698
diff changeset
232 return html;
8692
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
233 }
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
234
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
235 static gchar *
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
236 clipboard_html_to_win32(char *html) {
8693
e4579335a6f6 [gaim-migrate @ 9446]
Kevin Stange <kstange@pidgin.im>
parents: 8692
diff changeset
237 int length;
11240
cd4ca16ff57c [gaim-migrate @ 13399]
Richard Laager <rlaager@pidgin.im>
parents: 11234
diff changeset
238 GString *clipboard;
8692
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
239
8693
e4579335a6f6 [gaim-migrate @ 9446]
Kevin Stange <kstange@pidgin.im>
parents: 8692
diff changeset
240 if (html == NULL)
e4579335a6f6 [gaim-migrate @ 9446]
Kevin Stange <kstange@pidgin.im>
parents: 8692
diff changeset
241 return NULL;
8692
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
242
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
243 length = strlen(html);
9465
652dcd45db7d [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
244 clipboard = g_string_new ("Version:1.0\r\n");
8692
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
245 g_string_append(clipboard, "StartHTML:0000000105\r\n");
18665
157820042a6f Fix #1727 and also plug a possible leak and make a little efficiency improvement to the win32 clipboard handling.
Daniel Atallah <datallah@pidgin.im>
parents: 18633
diff changeset
246 g_string_append_printf(clipboard, "EndHTML:%010d\r\n", 147 + length);
9465
652dcd45db7d [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
247 g_string_append(clipboard, "StartFragment:0000000127\r\n");
18665
157820042a6f Fix #1727 and also plug a possible leak and make a little efficiency improvement to the win32 clipboard handling.
Daniel Atallah <datallah@pidgin.im>
parents: 18633
diff changeset
248 g_string_append_printf(clipboard, "EndFragment:%010d\r\n", 127 + length);
9465
652dcd45db7d [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
249 g_string_append(clipboard, "<!--StartFragment-->\r\n");
8692
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
250 g_string_append(clipboard, html);
9465
652dcd45db7d [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
251 g_string_append(clipboard, "\r\n<!--EndFragment-->");
14101
89a79c2a971e [gaim-migrate @ 16643]
Mark Doliner <markdoliner@pidgin.im>
parents: 14097
diff changeset
252
89a79c2a971e [gaim-migrate @ 16643]
Mark Doliner <markdoliner@pidgin.im>
parents: 14097
diff changeset
253 return g_string_free(clipboard, FALSE);
8692
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
254 }
10901
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
255
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
256 static gboolean clipboard_paste_html_win32(GtkIMHtml *imhtml) {
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
257 gboolean pasted = FALSE;
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
258
15111
e427dd6f3b7e [gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents: 15093
diff changeset
259 /* Win32 clipboard format value, and functions to convert back and
e427dd6f3b7e [gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents: 15093
diff changeset
260 * forth between HTML and the clipboard format.
e427dd6f3b7e [gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents: 15093
diff changeset
261 */
e427dd6f3b7e [gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents: 15093
diff changeset
262 static UINT win_html_fmt = 0;
e427dd6f3b7e [gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents: 15093
diff changeset
263
e427dd6f3b7e [gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents: 15093
diff changeset
264 /* Register HTML Format as desired clipboard format */
e427dd6f3b7e [gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents: 15093
diff changeset
265 if (!win_html_fmt)
e427dd6f3b7e [gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents: 15093
diff changeset
266 win_html_fmt = RegisterClipboardFormat("HTML Format");
e427dd6f3b7e [gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents: 15093
diff changeset
267
10901
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
268 if (gtk_text_view_get_editable(GTK_TEXT_VIEW(imhtml))
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
269 && IsClipboardFormatAvailable(win_html_fmt)) {
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
270 gboolean error_reading_clipboard = FALSE;
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
271 HWND hwnd = GDK_WINDOW_HWND(GTK_WIDGET(imhtml)->window);
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
272
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
273 if (OpenClipboard(hwnd)) {
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
274 HGLOBAL hdata = GetClipboardData(win_html_fmt);
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
275 if (hdata == NULL) {
15111
e427dd6f3b7e [gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents: 15093
diff changeset
276 if (GetLastError() != ERROR_SUCCESS)
e427dd6f3b7e [gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents: 15093
diff changeset
277 error_reading_clipboard = TRUE;
10901
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
278 } else {
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
279 char *buffer = GlobalLock(hdata);
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
280 if (buffer == NULL) {
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
281 error_reading_clipboard = TRUE;
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
282 } else {
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
283 char *text = clipboard_win32_to_html(
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
284 buffer);
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
285 imhtml_paste_insert(imhtml, text,
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
286 FALSE);
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
287 g_free(text);
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
288 pasted = TRUE;
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
289 }
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
290 GlobalUnlock(hdata);
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
291 }
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
292
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
293 CloseClipboard();
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
294 } else {
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
295 error_reading_clipboard = TRUE;
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
296 }
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
297
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
298 if (error_reading_clipboard) {
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
299 gchar *err_msg = g_win32_error_message(GetLastError());
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15865
diff changeset
300 purple_debug_info("html clipboard",
10901
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
301 "Unable to read clipboard data: %s\n",
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
302 err_msg ? err_msg : "Unknown Error");
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
303 g_free(err_msg);
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
304 }
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
305 }
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
306
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
307 return pasted;
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
308 }
8692
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
309 #endif
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
310
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
311 static GtkSmileyTree*
22104
56970903b8e9 Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@pidgin.im>
parents: 22100
diff changeset
312 gtk_smiley_tree_new (void)
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
313 {
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
314 return g_new0 (GtkSmileyTree, 1);
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
315 }
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
316
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
317 static void
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
318 gtk_smiley_tree_insert (GtkSmileyTree *tree,
4263
054b3ea4e7c5 [gaim-migrate @ 4514]
Sean Egan <seanegan@pidgin.im>
parents: 4253
diff changeset
319 GtkIMHtmlSmiley *smiley)
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
320 {
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
321 GtkSmileyTree *t = tree;
4263
054b3ea4e7c5 [gaim-migrate @ 4514]
Sean Egan <seanegan@pidgin.im>
parents: 4253
diff changeset
322 const gchar *x = smiley->smile;
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
323
12229
ad8d3ae8fc1b [gaim-migrate @ 14531]
Michael Carlson <corfe83@users.sourceforge.net>
parents: 12072
diff changeset
324 if (!(*x))
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
325 return;
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
326
12229
ad8d3ae8fc1b [gaim-migrate @ 14531]
Michael Carlson <corfe83@users.sourceforge.net>
parents: 12072
diff changeset
327 do {
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
328 gchar *pos;
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
329 gint index;
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
330
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
331 if (!t->values)
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
332 t->values = g_string_new ("");
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
333
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
334 pos = strchr (t->values->str, *x);
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
335 if (!pos) {
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
336 t->values = g_string_append_c (t->values, *x);
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
337 index = t->values->len - 1;
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
338 t->children = g_realloc (t->children, t->values->len * sizeof (GtkSmileyTree *));
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
339 t->children [index] = g_new0 (GtkSmileyTree, 1);
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
340 } else
7386
9cccb3792018 [gaim-migrate @ 7981]
Luke Schierer <lschiere@pidgin.im>
parents: 7384
diff changeset
341 index = GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
342
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
343 t = t->children [index];
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
344
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
345 x++;
12229
ad8d3ae8fc1b [gaim-migrate @ 14531]
Michael Carlson <corfe83@users.sourceforge.net>
parents: 12072
diff changeset
346 } while (*x);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
347
4263
054b3ea4e7c5 [gaim-migrate @ 4514]
Sean Egan <seanegan@pidgin.im>
parents: 4253
diff changeset
348 t->image = smiley;
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
349 }
4041
6336d3d3785e [gaim-migrate @ 4249]
Sean Egan <seanegan@pidgin.im>
parents: 4032
diff changeset
350
4263
054b3ea4e7c5 [gaim-migrate @ 4514]
Sean Egan <seanegan@pidgin.im>
parents: 4253
diff changeset
351
11677
89c2ab8d2ebf [gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents: 11586
diff changeset
352 static void
89c2ab8d2ebf [gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents: 11586
diff changeset
353 gtk_smiley_tree_destroy (GtkSmileyTree *tree)
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
354 {
11701
8cf812de5e92 [gaim-migrate @ 13992]
Michael Carlson <corfe83@users.sourceforge.net>
parents: 11677
diff changeset
355 GSList *list = g_slist_prepend (NULL, tree);
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
356
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
357 while (list) {
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
358 GtkSmileyTree *t = list->data;
12229
ad8d3ae8fc1b [gaim-migrate @ 14531]
Michael Carlson <corfe83@users.sourceforge.net>
parents: 12072
diff changeset
359 gsize i;
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
360 list = g_slist_remove(list, t);
7384
c2ed41f62aae [gaim-migrate @ 7979]
Nathan Walp <nwalp@pidgin.im>
parents: 7371
diff changeset
361 if (t && t->values) {
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
362 for (i = 0; i < t->values->len; i++)
11701
8cf812de5e92 [gaim-migrate @ 13992]
Michael Carlson <corfe83@users.sourceforge.net>
parents: 11677
diff changeset
363 list = g_slist_prepend (list, t->children [i]);
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
364 g_string_free (t->values, TRUE);
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
365 g_free (t->children);
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
366 }
25888
d0fdd378a635 Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents: 25854
diff changeset
367
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
368 g_free (t);
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
369 }
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
370 }
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
371
18968
2ddbe6473bc9 Cool! Override GtkTextView's size allocate function in GtkIMHtml to make sure that it stays scrolled to the bottom whenever it's resized. Fixes a major annoyance and possibly #938
Sean Egan <seanegan@pidgin.im>
parents: 18665
diff changeset
372 static void (*parent_size_allocate)(GtkWidget *widget, GtkAllocation *alloc);
2ddbe6473bc9 Cool! Override GtkTextView's size allocate function in GtkIMHtml to make sure that it stays scrolled to the bottom whenever it's resized. Fixes a major annoyance and possibly #938
Sean Egan <seanegan@pidgin.im>
parents: 18665
diff changeset
373
2ddbe6473bc9 Cool! Override GtkTextView's size allocate function in GtkIMHtml to make sure that it stays scrolled to the bottom whenever it's resized. Fixes a major annoyance and possibly #938
Sean Egan <seanegan@pidgin.im>
parents: 18665
diff changeset
374 static void gtk_imhtml_size_allocate(GtkWidget *widget, GtkAllocation *alloc)
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
375 {
18968
2ddbe6473bc9 Cool! Override GtkTextView's size allocate function in GtkIMHtml to make sure that it stays scrolled to the bottom whenever it's resized. Fixes a major annoyance and possibly #938
Sean Egan <seanegan@pidgin.im>
parents: 18665
diff changeset
376 GtkIMHtml *imhtml = GTK_IMHTML(widget);
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
377 GdkRectangle rect;
8726
3db8ac8e0ebb [gaim-migrate @ 9481]
Tim Ringenbach <marv@pidgin.im>
parents: 8719
diff changeset
378 int xminus;
18968
2ddbe6473bc9 Cool! Override GtkTextView's size allocate function in GtkIMHtml to make sure that it stays scrolled to the bottom whenever it's resized. Fixes a major annoyance and possibly #938
Sean Egan <seanegan@pidgin.im>
parents: 18665
diff changeset
379 int height = 0, y = 0;
2ddbe6473bc9 Cool! Override GtkTextView's size allocate function in GtkIMHtml to make sure that it stays scrolled to the bottom whenever it's resized. Fixes a major annoyance and possibly #938
Sean Egan <seanegan@pidgin.im>
parents: 18665
diff changeset
380 GtkTextIter iter;
2ddbe6473bc9 Cool! Override GtkTextView's size allocate function in GtkIMHtml to make sure that it stays scrolled to the bottom whenever it's resized. Fixes a major annoyance and possibly #938
Sean Egan <seanegan@pidgin.im>
parents: 18665
diff changeset
381 gboolean scroll = TRUE;
2ddbe6473bc9 Cool! Override GtkTextView's size allocate function in GtkIMHtml to make sure that it stays scrolled to the bottom whenever it's resized. Fixes a major annoyance and possibly #938
Sean Egan <seanegan@pidgin.im>
parents: 18665
diff changeset
382
22803
e1f64090d32e Do not show tooltips for <HR> or <IMG>s in gtkimhtml. Fixes #5480.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22772
diff changeset
383 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter);
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
384
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
385 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(widget), &rect);
22803
e1f64090d32e Do not show tooltips for <HR> or <IMG>s in gtkimhtml. Fixes #5480.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22772
diff changeset
386 gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(imhtml), &iter, &y, &height);
e1f64090d32e Do not show tooltips for <HR> or <IMG>s in gtkimhtml. Fixes #5480.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22772
diff changeset
387
e1f64090d32e Do not show tooltips for <HR> or <IMG>s in gtkimhtml. Fixes #5480.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22772
diff changeset
388 if (((y + height) - (rect.y + rect.height)) > height &&
e1f64090d32e Do not show tooltips for <HR> or <IMG>s in gtkimhtml. Fixes #5480.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22772
diff changeset
389 gtk_text_buffer_get_char_count(imhtml->text_buffer)) {
e1f64090d32e Do not show tooltips for <HR> or <IMG>s in gtkimhtml. Fixes #5480.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22772
diff changeset
390 scroll = FALSE;
e1f64090d32e Do not show tooltips for <HR> or <IMG>s in gtkimhtml. Fixes #5480.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22772
diff changeset
391 }
e1f64090d32e Do not show tooltips for <HR> or <IMG>s in gtkimhtml. Fixes #5480.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22772
diff changeset
392
e1f64090d32e Do not show tooltips for <HR> or <IMG>s in gtkimhtml. Fixes #5480.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22772
diff changeset
393 if(imhtml->old_rect.width != rect.width || imhtml->old_rect.height != rect.height) {
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
394 GList *iter = GTK_IMHTML(widget)->scalables;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
395
8726
3db8ac8e0ebb [gaim-migrate @ 9481]
Tim Ringenbach <marv@pidgin.im>
parents: 8719
diff changeset
396 xminus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(widget)) +
3db8ac8e0ebb [gaim-migrate @ 9481]
Tim Ringenbach <marv@pidgin.im>
parents: 8719
diff changeset
397 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(widget));
3db8ac8e0ebb [gaim-migrate @ 9481]
Tim Ringenbach <marv@pidgin.im>
parents: 8719
diff changeset
398
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
399 while(iter){
11224
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
400 struct scalable_data *sd = iter->data;
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
401 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(sd->scalable);
8726
3db8ac8e0ebb [gaim-migrate @ 9481]
Tim Ringenbach <marv@pidgin.im>
parents: 8719
diff changeset
402 scale->scale(scale, rect.width - xminus, rect.height);
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
403
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
404 iter = iter->next;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
405 }
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
406 }
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
407
18968
2ddbe6473bc9 Cool! Override GtkTextView's size allocate function in GtkIMHtml to make sure that it stays scrolled to the bottom whenever it's resized. Fixes a major annoyance and possibly #938
Sean Egan <seanegan@pidgin.im>
parents: 18665
diff changeset
408 imhtml->old_rect = rect;
2ddbe6473bc9 Cool! Override GtkTextView's size allocate function in GtkIMHtml to make sure that it stays scrolled to the bottom whenever it's resized. Fixes a major annoyance and possibly #938
Sean Egan <seanegan@pidgin.im>
parents: 18665
diff changeset
409 parent_size_allocate(widget, alloc);
22803
e1f64090d32e Do not show tooltips for <HR> or <IMG>s in gtkimhtml. Fixes #5480.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22772
diff changeset
410
18985
877a49e0979d And fix smooth scroll too
Sean Egan <seanegan@pidgin.im>
parents: 18984
diff changeset
411 /* Don't scroll here if we're in the middle of a smooth scroll */
19326
d3071a414d6b Don't scroll to bottom if imhtml is not realized. Fixes #2320
Sean Egan <seanegan@pidgin.im>
parents: 19325
diff changeset
412 if (scroll && imhtml->scroll_time == NULL &&
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
413 gtk_widget_get_realized(GTK_WIDGET(imhtml)))
22803
e1f64090d32e Do not show tooltips for <HR> or <IMG>s in gtkimhtml. Fixes #5480.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22772
diff changeset
414 gtk_imhtml_scroll_to_end(imhtml, FALSE);
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
415 }
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
416
23227
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
417 #define DEFAULT_SEND_COLOR "#204a87"
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
418 #define DEFAULT_RECV_COLOR "#cc0000"
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
419 #define DEFAULT_HIGHLIGHT_COLOR "#AF7F00"
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
420 #define DEFAULT_ACTION_COLOR "#062585"
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
421 #define DEFAULT_WHISPER_ACTION_COLOR "#6C2585"
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
422 #define DEFAULT_WHISPER_COLOR "#00FF00"
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
423
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
424 static void (*parent_style_set)(GtkWidget *widget, GtkStyle *prev_style);
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
425
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
426 static void
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
427 gtk_imhtml_style_set(GtkWidget *widget, GtkStyle *prev_style)
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
428 {
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
429 int i;
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
430 struct {
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
431 const char *tag;
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
432 const char *color;
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
433 const char *def;
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
434 } styles[] = {
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
435 {"send-name", "send-name-color", DEFAULT_SEND_COLOR},
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
436 {"receive-name", "receive-name-color", DEFAULT_RECV_COLOR},
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
437 {"highlight-name", "highlight-name-color", DEFAULT_HIGHLIGHT_COLOR},
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
438 {"action-name", "action-name-color", DEFAULT_ACTION_COLOR},
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
439 {"whisper-action-name", "whisper-action-name-color", DEFAULT_WHISPER_ACTION_COLOR},
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
440 {"whisper-name", "whisper-name-color", DEFAULT_WHISPER_COLOR},
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
441 {NULL, NULL, NULL}
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
442 };
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
443 GtkIMHtml *imhtml = GTK_IMHTML(widget);
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
444 GtkTextTagTable *table = gtk_text_buffer_get_tag_table(imhtml->text_buffer);
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
445
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
446 for (i = 0; styles[i].tag; i++) {
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
447 GdkColor *color = NULL;
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
448 GtkTextTag *tag = gtk_text_tag_table_lookup(table, styles[i].tag);
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
449 if (!tag) {
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
450 purple_debug_warning("gtkimhtml", "Cannot find tag '%s'. This should never happen. Please file a bug.\n", styles[i].tag);
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
451 continue;
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
452 }
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
453 gtk_widget_style_get(widget, styles[i].color, &color, NULL);
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
454 if (color) {
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
455 g_object_set(tag, "foreground-gdk", color, NULL);
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
456 gdk_color_free(color);
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
457 } else {
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
458 GdkColor defcolor;
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
459 gdk_color_parse(styles[i].def, &defcolor);
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
460 g_object_set(tag, "foreground-gdk", &defcolor, NULL);
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
461 }
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
462 }
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
463 parent_style_set(widget, prev_style);
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
464 }
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
465
28935
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
466 static gboolean
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
467 imhtml_get_iter_bounds(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end)
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
468 {
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
469 if (imhtml->wbfo) {
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
470 gtk_text_buffer_get_bounds(imhtml->text_buffer, start, end);
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
471 return TRUE;
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
472 } else if (imhtml->editable) {
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
473 if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, start, end)) {
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
474 GtkTextMark *mark = gtk_text_buffer_get_insert(imhtml->text_buffer);
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
475 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, start, mark);
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
476 *end = *start;
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
477 }
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
478 return TRUE;
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
479 }
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
480
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
481 return FALSE;
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
482 }
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
483
24328
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
484 static void
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
485 gtk_imhtml_set_link_color(GtkIMHtml *imhtml, GtkTextTag *tag)
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
486 {
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
487 GdkColor *color = NULL;
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
488 gboolean visited = !!g_object_get_data(G_OBJECT(tag), "visited");
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
489 gtk_widget_style_get(GTK_WIDGET(imhtml), visited ? "hyperlink-visited-color" : "hyperlink-color", &color, NULL);
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
490 if (color) {
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
491 g_object_set(G_OBJECT(tag), "foreground-gdk", color, NULL);
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
492 gdk_color_free(color);
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
493 } else {
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
494 g_object_set(G_OBJECT(tag), "foreground", visited ? "#800000" : "blue", NULL);
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
495 }
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
496 }
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
497
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
498 static gint
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
499 gtk_imhtml_tip_paint (GtkIMHtml *imhtml)
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
500 {
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
501 PangoLayout *layout;
32410
3d78feb90b9c don't use GDK_DRAWABLE
Marcus Lundblad <malu@pidgin.im>
parents: 32407
diff changeset
502 cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(imhtml->tip_window));
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
503
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
504 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE);
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
505
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
506 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip);
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
507
32407
683883fbfcd3 fixed some indentation
Marcus Lundblad <malu@pidgin.im>
parents: 32394
diff changeset
508 gtk_paint_flat_box (gtk_widget_get_style(imhtml->tip_window), cr,
683883fbfcd3 fixed some indentation
Marcus Lundblad <malu@pidgin.im>
parents: 32394
diff changeset
509 GTK_STATE_NORMAL, GTK_SHADOW_OUT, imhtml->tip_window, "tooltip",
683883fbfcd3 fixed some indentation
Marcus Lundblad <malu@pidgin.im>
parents: 32394
diff changeset
510 0, 0, -1, -1);
683883fbfcd3 fixed some indentation
Marcus Lundblad <malu@pidgin.im>
parents: 32394
diff changeset
511
683883fbfcd3 fixed some indentation
Marcus Lundblad <malu@pidgin.im>
parents: 32394
diff changeset
512 gtk_paint_layout (gtk_widget_get_style(imhtml->tip_window), cr,
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
513 GTK_STATE_NORMAL, TRUE, imhtml->tip_window, NULL, 4, 4, layout);
32407
683883fbfcd3 fixed some indentation
Marcus Lundblad <malu@pidgin.im>
parents: 32394
diff changeset
514
683883fbfcd3 fixed some indentation
Marcus Lundblad <malu@pidgin.im>
parents: 32394
diff changeset
515 cairo_destroy(cr);
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
516 g_object_unref(layout);
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
517 return FALSE;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
518 }
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
519
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
520 static gint
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
521 gtk_imhtml_tip (gpointer data)
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
522 {
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
523 GtkIMHtml *imhtml = data;
8526
cea38c0015e6 [gaim-migrate @ 9265]
Daniel Atallah <datallah@pidgin.im>
parents: 8519
diff changeset
524 PangoFontMetrics *font_metrics;
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
525 PangoLayout *layout;
8526
cea38c0015e6 [gaim-migrate @ 9265]
Daniel Atallah <datallah@pidgin.im>
parents: 8519
diff changeset
526 PangoFont *font;
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
527 GtkStyle *style = gtk_widget_get_style(imhtml->tip_window);
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
528 GtkAllocation allocation;
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
529 gint gap, x, y, h, w, scr_w, baseline_skip;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
530
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
531 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE);
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
532
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
533 gtk_widget_get_allocation(GTK_WIDGET(imhtml), &allocation);
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
534
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
535 if (!imhtml->tip || !gtk_widget_is_drawable(GTK_WIDGET(imhtml))) {
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
536 imhtml->tip_timer = 0;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
537 return FALSE;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
538 }
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
539
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
540 if (imhtml->tip_window){
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
541 gtk_widget_destroy (imhtml->tip_window);
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
542 imhtml->tip_window = NULL;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
543 }
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
544
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
545 imhtml->tip_timer = 0;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
546 imhtml->tip_window = gtk_window_new (GTK_WINDOW_POPUP);
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
547 gtk_widget_set_app_paintable (imhtml->tip_window, TRUE);
29153
ee7369d8f401 Call gtk_window_set_title() for the GtkIMHtml tip window, to avoid the
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 28940
diff changeset
548 gtk_window_set_title(GTK_WINDOW(imhtml->tip_window), "GtkIMHtml");
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
549 gtk_window_set_resizable (GTK_WINDOW (imhtml->tip_window), FALSE);
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
550 gtk_widget_set_name (imhtml->tip_window, "gtk-tooltips");
22594
4fe64dc3d266 Set the TOOLTIP hint on imhtml link tooltips. Thanks to Danny Baumann for
Will Thompson <resiak@pidgin.im>
parents: 22532
diff changeset
551 gtk_window_set_type_hint (GTK_WINDOW (imhtml->tip_window),
4fe64dc3d266 Set the TOOLTIP hint on imhtml link tooltips. Thanks to Danny Baumann for
Will Thompson <resiak@pidgin.im>
parents: 22532
diff changeset
552 GDK_WINDOW_TYPE_HINT_TOOLTIP);
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
553 g_signal_connect_swapped (G_OBJECT (imhtml->tip_window), "expose_event",
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
554 G_CALLBACK (gtk_imhtml_tip_paint), imhtml);
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
555
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
556 gtk_widget_ensure_style (imhtml->tip_window);
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
557 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip);
8526
cea38c0015e6 [gaim-migrate @ 9265]
Daniel Atallah <datallah@pidgin.im>
parents: 8519
diff changeset
558 font = pango_context_load_font(pango_layout_get_context(layout),
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
559 style->font_desc);
8526
cea38c0015e6 [gaim-migrate @ 9265]
Daniel Atallah <datallah@pidgin.im>
parents: 8519
diff changeset
560
cea38c0015e6 [gaim-migrate @ 9265]
Daniel Atallah <datallah@pidgin.im>
parents: 8519
diff changeset
561 if (font == NULL) {
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
562 char *tmp = pango_font_description_to_string(style->font_desc);
8526
cea38c0015e6 [gaim-migrate @ 9265]
Daniel Atallah <datallah@pidgin.im>
parents: 8519
diff changeset
563
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15865
diff changeset
564 purple_debug(PURPLE_DEBUG_ERROR, "gtk_imhtml_tip",
8526
cea38c0015e6 [gaim-migrate @ 9265]
Daniel Atallah <datallah@pidgin.im>
parents: 8519
diff changeset
565 "pango_context_load_font() couldn't load font: '%s'\n",
cea38c0015e6 [gaim-migrate @ 9265]
Daniel Atallah <datallah@pidgin.im>
parents: 8519
diff changeset
566 tmp);
cea38c0015e6 [gaim-migrate @ 9265]
Daniel Atallah <datallah@pidgin.im>
parents: 8519
diff changeset
567 g_free(tmp);
cea38c0015e6 [gaim-migrate @ 9265]
Daniel Atallah <datallah@pidgin.im>
parents: 8519
diff changeset
568
23174
6a5b2c601492 applied changes from a341780d901f6351a5cf768a08d30c8882d6cf2f
Daniel Atallah <datallah@pidgin.im>
parents: 22970
diff changeset
569 g_object_unref(layout);
8526
cea38c0015e6 [gaim-migrate @ 9265]
Daniel Atallah <datallah@pidgin.im>
parents: 8519
diff changeset
570 return FALSE;
cea38c0015e6 [gaim-migrate @ 9265]
Daniel Atallah <datallah@pidgin.im>
parents: 8519
diff changeset
571 }
cea38c0015e6 [gaim-migrate @ 9265]
Daniel Atallah <datallah@pidgin.im>
parents: 8519
diff changeset
572
cea38c0015e6 [gaim-migrate @ 9265]
Daniel Atallah <datallah@pidgin.im>
parents: 8519
diff changeset
573 font_metrics = pango_font_get_metrics(font, NULL);
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
574
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
575 pango_layout_get_pixel_size(layout, &scr_w, NULL);
8526
cea38c0015e6 [gaim-migrate @ 9265]
Daniel Atallah <datallah@pidgin.im>
parents: 8519
diff changeset
576 gap = PANGO_PIXELS((pango_font_metrics_get_ascent(font_metrics) +
cea38c0015e6 [gaim-migrate @ 9265]
Daniel Atallah <datallah@pidgin.im>
parents: 8519
diff changeset
577 pango_font_metrics_get_descent(font_metrics))/ 4);
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
578
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
579 if (gap < 2)
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
580 gap = 2;
8526
cea38c0015e6 [gaim-migrate @ 9265]
Daniel Atallah <datallah@pidgin.im>
parents: 8519
diff changeset
581 baseline_skip = PANGO_PIXELS(pango_font_metrics_get_ascent(font_metrics) +
cea38c0015e6 [gaim-migrate @ 9265]
Daniel Atallah <datallah@pidgin.im>
parents: 8519
diff changeset
582 pango_font_metrics_get_descent(font_metrics));
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
583 w = 8 + scr_w;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
584 h = 8 + baseline_skip;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
585
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
586 gdk_window_get_pointer (NULL, &x, &y, NULL);
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
587 if ((!gtk_widget_get_has_window(GTK_WIDGET(imhtml))))
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
588 y += allocation.y;
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
589
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
590 scr_w = gdk_screen_width();
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
591
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
592 x -= ((w >> 1) + 4);
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
593
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
594 if ((x + w) > scr_w)
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
595 x -= (x + w) - scr_w;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
596 else if (x < 0)
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
597 x = 0;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
598
8526
cea38c0015e6 [gaim-migrate @ 9265]
Daniel Atallah <datallah@pidgin.im>
parents: 8519
diff changeset
599 y = y + PANGO_PIXELS(pango_font_metrics_get_ascent(font_metrics) +
cea38c0015e6 [gaim-migrate @ 9265]
Daniel Atallah <datallah@pidgin.im>
parents: 8519
diff changeset
600 pango_font_metrics_get_descent(font_metrics));
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
601
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
602 gtk_widget_set_size_request (imhtml->tip_window, w, h);
15865
e046bdae3964 Move the tooltip window before showing the tooltip to avoid a transient
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15577
diff changeset
603 gtk_window_move (GTK_WINDOW(imhtml->tip_window), x, y);
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
604 gtk_widget_show (imhtml->tip_window);
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
605
8526
cea38c0015e6 [gaim-migrate @ 9265]
Daniel Atallah <datallah@pidgin.im>
parents: 8519
diff changeset
606 pango_font_metrics_unref(font_metrics);
23174
6a5b2c601492 applied changes from a341780d901f6351a5cf768a08d30c8882d6cf2f
Daniel Atallah <datallah@pidgin.im>
parents: 22970
diff changeset
607 g_object_unref(font);
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
608 g_object_unref(layout);
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
609
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
610 return FALSE;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
611 }
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
612
11844
57ad7c52cc9c [gaim-migrate @ 14135]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 11840
diff changeset
613 static gboolean
57ad7c52cc9c [gaim-migrate @ 14135]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 11840
diff changeset
614 gtk_motion_event_notify(GtkWidget *imhtml, GdkEventMotion *event, gpointer data)
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
615 {
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
616 GtkTextIter iter;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
617 GdkWindow *win = event->window;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
618 int x, y;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
619 char *tip = NULL;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
620 GSList *tags = NULL, *templist = NULL;
10799
69ccc5c5518c [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
621 GtkTextTag *tag = NULL, *oldprelit_tag;
18543
c590aed61aa4 Show tooltip for smileys. Fixes #1981.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18371
diff changeset
622 GtkTextChildAnchor* anchor;
c590aed61aa4 Show tooltip for smileys. Fixes #1981.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18371
diff changeset
623 gboolean hand = TRUE;
29309
b94fa8bc1a03 Change the cursor and act on double click on usernames in chat history.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29288
diff changeset
624 GdkCursor *cursor = NULL;
10799
69ccc5c5518c [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
625
69ccc5c5518c [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
626 oldprelit_tag = GTK_IMHTML(imhtml)->prelit_tag;
69ccc5c5518c [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
627
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
628 gdk_window_get_pointer(gtk_widget_get_window(GTK_WIDGET(imhtml)), NULL, NULL, NULL);
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
629 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(imhtml), GTK_TEXT_WINDOW_WIDGET,
10799
69ccc5c5518c [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
630 event->x, event->y, &x, &y);
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
631 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, x, y);
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
632 tags = gtk_text_iter_get_tags(&iter);
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
633
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
634 templist = tags;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
635 while (templist) {
10799
69ccc5c5518c [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
636 tag = templist->data;
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
637 tip = g_object_get_data(G_OBJECT(tag), "link_url");
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
638 if (tip)
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
639 break;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
640 templist = templist->next;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
641 }
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
642
24328
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
643 if (tip && (!tag || !g_object_get_data(G_OBJECT(tag), "visited"))) {
10799
69ccc5c5518c [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
644 GTK_IMHTML(imhtml)->prelit_tag = tag;
69ccc5c5518c [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
645 if (tag != oldprelit_tag) {
24328
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
646 GdkColor *pre = NULL;
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
647 gtk_widget_style_get(GTK_WIDGET(imhtml), "hyperlink-prelight-color", &pre, NULL);
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
648 if (pre) {
10799
69ccc5c5518c [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
649 g_object_set(G_OBJECT(tag), "foreground-gdk", pre, NULL);
24328
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
650 gdk_color_free(pre);
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
651 } else
12253
5025434b18f8 [gaim-migrate @ 14555]
Mark Doliner <markdoliner@pidgin.im>
parents: 12230
diff changeset
652 g_object_set(G_OBJECT(tag), "foreground", "#70a0ff", NULL);
10799
69ccc5c5518c [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
653 }
69ccc5c5518c [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
654 } else {
69ccc5c5518c [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
655 GTK_IMHTML(imhtml)->prelit_tag = NULL;
69ccc5c5518c [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
656 }
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
657
10834
5fd1dfd395e8 [gaim-migrate @ 12505]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10826
diff changeset
658 if ((oldprelit_tag != NULL) && (GTK_IMHTML(imhtml)->prelit_tag != oldprelit_tag)) {
24328
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
659 gtk_imhtml_set_link_color(GTK_IMHTML(imhtml), oldprelit_tag);
10799
69ccc5c5518c [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
660 }
69ccc5c5518c [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
661
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
662 if (GTK_IMHTML(imhtml)->tip) {
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
663 if ((tip == GTK_IMHTML(imhtml)->tip)) {
21069
fcc0f4eb692a Leak fix.
Daniel Atallah <datallah@pidgin.im>
parents: 21063
diff changeset
664 g_slist_free(tags);
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
665 return FALSE;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
666 }
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
667 /* We've left the cell. Remove the timeout and create a new one below */
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
668 if (GTK_IMHTML(imhtml)->tip_window) {
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
669 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window);
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
670 GTK_IMHTML(imhtml)->tip_window = NULL;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
671 }
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
672 if (GTK_IMHTML(imhtml)->editable)
29309
b94fa8bc1a03 Change the cursor and act on double click on usernames in chat history.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29288
diff changeset
673 cursor = GTK_IMHTML(imhtml)->text_cursor;
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
674 else
29309
b94fa8bc1a03 Change the cursor and act on double click on usernames in chat history.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29288
diff changeset
675 cursor = GTK_IMHTML(imhtml)->arrow_cursor;
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
676 if (GTK_IMHTML(imhtml)->tip_timer)
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
677 g_source_remove(GTK_IMHTML(imhtml)->tip_timer);
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
678 GTK_IMHTML(imhtml)->tip_timer = 0;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
679 }
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
680
18543
c590aed61aa4 Show tooltip for smileys. Fixes #1981.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18371
diff changeset
681 /* If we don't have a tip from a URL, let's see if we have a tip from a smiley */
c590aed61aa4 Show tooltip for smileys. Fixes #1981.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18371
diff changeset
682 anchor = gtk_text_iter_get_child_anchor(&iter);
c590aed61aa4 Show tooltip for smileys. Fixes #1981.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18371
diff changeset
683 if (anchor) {
22803
e1f64090d32e Do not show tooltips for <HR> or <IMG>s in gtkimhtml. Fixes #5480.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22772
diff changeset
684 tip = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_tiptext");
18543
c590aed61aa4 Show tooltip for smileys. Fixes #1981.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18371
diff changeset
685 hand = FALSE;
c590aed61aa4 Show tooltip for smileys. Fixes #1981.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18371
diff changeset
686 }
c590aed61aa4 Show tooltip for smileys. Fixes #1981.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18371
diff changeset
687
22803
e1f64090d32e Do not show tooltips for <HR> or <IMG>s in gtkimhtml. Fixes #5480.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22772
diff changeset
688 if (tip && *tip) {
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
689 GTK_IMHTML(imhtml)->tip_timer = g_timeout_add (TOOLTIP_TIMEOUT,
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
690 gtk_imhtml_tip, imhtml);
29309
b94fa8bc1a03 Change the cursor and act on double click on usernames in chat history.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29288
diff changeset
691 } else if (!tip) {
b94fa8bc1a03 Change the cursor and act on double click on usernames in chat history.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29288
diff changeset
692 hand = FALSE;
b94fa8bc1a03 Change the cursor and act on double click on usernames in chat history.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29288
diff changeset
693 for (templist = tags; templist; templist = templist->next) {
b94fa8bc1a03 Change the cursor and act on double click on usernames in chat history.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29288
diff changeset
694 tag = templist->data;
b94fa8bc1a03 Change the cursor and act on double click on usernames in chat history.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29288
diff changeset
695 if ((tip = g_object_get_data(G_OBJECT(tag), "cursor"))) {
b94fa8bc1a03 Change the cursor and act on double click on usernames in chat history.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29288
diff changeset
696 hand = TRUE;
b94fa8bc1a03 Change the cursor and act on double click on usernames in chat history.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29288
diff changeset
697 break;
b94fa8bc1a03 Change the cursor and act on double click on usernames in chat history.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29288
diff changeset
698 }
b94fa8bc1a03 Change the cursor and act on double click on usernames in chat history.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29288
diff changeset
699 }
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
700 }
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
701
29309
b94fa8bc1a03 Change the cursor and act on double click on usernames in chat history.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29288
diff changeset
702 if (hand && !(GTK_IMHTML(imhtml)->editable))
b94fa8bc1a03 Change the cursor and act on double click on usernames in chat history.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29288
diff changeset
703 cursor = GTK_IMHTML(imhtml)->hand_cursor;
b94fa8bc1a03 Change the cursor and act on double click on usernames in chat history.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29288
diff changeset
704
b94fa8bc1a03 Change the cursor and act on double click on usernames in chat history.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29288
diff changeset
705 if (cursor)
b94fa8bc1a03 Change the cursor and act on double click on usernames in chat history.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29288
diff changeset
706 gdk_window_set_cursor(win, cursor);
b94fa8bc1a03 Change the cursor and act on double click on usernames in chat history.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29288
diff changeset
707
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
708 GTK_IMHTML(imhtml)->tip = tip;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
709 g_slist_free(tags);
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
710 return FALSE;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
711 }
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
712
11677
89c2ab8d2ebf [gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents: 11586
diff changeset
713 static gboolean
89c2ab8d2ebf [gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents: 11586
diff changeset
714 gtk_enter_event_notify(GtkWidget *imhtml, GdkEventCrossing *event, gpointer data)
10946
63a41710fc94 [gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents: 10936
diff changeset
715 {
63a41710fc94 [gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents: 10936
diff changeset
716 if (GTK_IMHTML(imhtml)->editable)
63a41710fc94 [gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents: 10936
diff changeset
717 gdk_window_set_cursor(
63a41710fc94 [gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents: 10936
diff changeset
718 gtk_text_view_get_window(GTK_TEXT_VIEW(imhtml),
63a41710fc94 [gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents: 10936
diff changeset
719 GTK_TEXT_WINDOW_TEXT),
63a41710fc94 [gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents: 10936
diff changeset
720 GTK_IMHTML(imhtml)->text_cursor);
63a41710fc94 [gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents: 10936
diff changeset
721 else
63a41710fc94 [gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents: 10936
diff changeset
722 gdk_window_set_cursor(
63a41710fc94 [gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents: 10936
diff changeset
723 gtk_text_view_get_window(GTK_TEXT_VIEW(imhtml),
63a41710fc94 [gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents: 10936
diff changeset
724 GTK_TEXT_WINDOW_TEXT),
63a41710fc94 [gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents: 10936
diff changeset
725 GTK_IMHTML(imhtml)->arrow_cursor);
63a41710fc94 [gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents: 10936
diff changeset
726
63a41710fc94 [gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents: 10936
diff changeset
727 /* propagate the event normally */
63a41710fc94 [gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents: 10936
diff changeset
728 return FALSE;
63a41710fc94 [gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents: 10936
diff changeset
729 }
63a41710fc94 [gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents: 10936
diff changeset
730
11677
89c2ab8d2ebf [gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents: 11586
diff changeset
731 static gboolean
89c2ab8d2ebf [gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents: 11586
diff changeset
732 gtk_leave_event_notify(GtkWidget *imhtml, GdkEventCrossing *event, gpointer data)
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
733 {
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
734 /* when leaving the widget, clear any current & pending tooltips and restore the cursor */
10799
69ccc5c5518c [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
735 if (GTK_IMHTML(imhtml)->prelit_tag) {
24328
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
736 gtk_imhtml_set_link_color(GTK_IMHTML(imhtml), GTK_IMHTML(imhtml)->prelit_tag);
10799
69ccc5c5518c [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
737 GTK_IMHTML(imhtml)->prelit_tag = NULL;
69ccc5c5518c [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
738 }
69ccc5c5518c [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
739
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
740 if (GTK_IMHTML(imhtml)->tip_window) {
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
741 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window);
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
742 GTK_IMHTML(imhtml)->tip_window = NULL;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
743 }
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
744 if (GTK_IMHTML(imhtml)->tip_timer) {
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
745 g_source_remove(GTK_IMHTML(imhtml)->tip_timer);
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
746 GTK_IMHTML(imhtml)->tip_timer = 0;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
747 }
10946
63a41710fc94 [gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents: 10936
diff changeset
748 gdk_window_set_cursor(
63a41710fc94 [gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents: 10936
diff changeset
749 gtk_text_view_get_window(GTK_TEXT_VIEW(imhtml),
63a41710fc94 [gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents: 10936
diff changeset
750 GTK_TEXT_WINDOW_TEXT), NULL);
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
751
8568
66907b37ce85 [gaim-migrate @ 9316]
Mark Doliner <markdoliner@pidgin.im>
parents: 8566
diff changeset
752 /* propagate the event normally */
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
753 return FALSE;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
754 }
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
755
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
756 /* TODO: I think this can be removed for GTK+ 3.0... */
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
757 #if 0
10692
f5c8ae17800b [gaim-migrate @ 12243]
Sean Egan <seanegan@pidgin.im>
parents: 10666
diff changeset
758 static gint
f5c8ae17800b [gaim-migrate @ 12243]
Sean Egan <seanegan@pidgin.im>
parents: 10666
diff changeset
759 gtk_imhtml_expose_event (GtkWidget *widget,
f5c8ae17800b [gaim-migrate @ 12243]
Sean Egan <seanegan@pidgin.im>
parents: 10666
diff changeset
760 GdkEventExpose *event)
f5c8ae17800b [gaim-migrate @ 12243]
Sean Egan <seanegan@pidgin.im>
parents: 10666
diff changeset
761 {
10776
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
762 GtkTextIter start, end, cur;
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
763 int buf_x, buf_y;
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
764 GdkRectangle visible_rect;
30566
8263353b04de Replace GdkGC in GtkIMHtml. Just in case you were wondering, it's now
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30417
diff changeset
765 cairo_t *cr = gdk_cairo_create(GDK_DRAWABLE(event->window));
10777
5a9df3199615 [gaim-migrate @ 12392]
Sean Egan <seanegan@pidgin.im>
parents: 10776
diff changeset
766 GdkColor gcolor;
10844
fb5b88957742 [gaim-migrate @ 12516]
Richard Laager <rlaager@pidgin.im>
parents: 10834
diff changeset
767
10776
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
768 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(widget), &visible_rect);
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
769 gtk_text_view_buffer_to_window_coords(GTK_TEXT_VIEW(widget),
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
770 GTK_TEXT_WINDOW_TEXT,
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
771 visible_rect.x,
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
772 visible_rect.y,
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
773 &visible_rect.x,
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
774 &visible_rect.y);
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
775
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
776 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(widget), GTK_TEXT_WINDOW_TEXT,
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
777 event->area.x, event->area.y, &buf_x, &buf_y);
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
778
10777
5a9df3199615 [gaim-migrate @ 12392]
Sean Egan <seanegan@pidgin.im>
parents: 10776
diff changeset
779 if (GTK_IMHTML(widget)->editable || GTK_IMHTML(widget)->wbfo) {
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
780
10777
5a9df3199615 [gaim-migrate @ 12392]
Sean Egan <seanegan@pidgin.im>
parents: 10776
diff changeset
781 if (GTK_IMHTML(widget)->edit.background) {
5a9df3199615 [gaim-migrate @ 12392]
Sean Egan <seanegan@pidgin.im>
parents: 10776
diff changeset
782 gdk_color_parse(GTK_IMHTML(widget)->edit.background, &gcolor);
30566
8263353b04de Replace GdkGC in GtkIMHtml. Just in case you were wondering, it's now
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30417
diff changeset
783 gdk_cairo_set_source_color(cr, &gcolor);
10777
5a9df3199615 [gaim-migrate @ 12392]
Sean Egan <seanegan@pidgin.im>
parents: 10776
diff changeset
784 } else {
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
785 gdk_cairo_set_source_color(cr,
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
786 &(gtk_widget_get_style(widget)->base[gtk_widget_get_state(widget)]));
10777
5a9df3199615 [gaim-migrate @ 12392]
Sean Egan <seanegan@pidgin.im>
parents: 10776
diff changeset
787 }
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
788
30566
8263353b04de Replace GdkGC in GtkIMHtml. Just in case you were wondering, it's now
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30417
diff changeset
789 cairo_rectangle(cr,
8263353b04de Replace GdkGC in GtkIMHtml. Just in case you were wondering, it's now
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30417
diff changeset
790 visible_rect.x, visible_rect.y,
8263353b04de Replace GdkGC in GtkIMHtml. Just in case you were wondering, it's now
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30417
diff changeset
791 visible_rect.width, visible_rect.height);
8263353b04de Replace GdkGC in GtkIMHtml. Just in case you were wondering, it's now
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30417
diff changeset
792 cairo_fill(cr);
8263353b04de Replace GdkGC in GtkIMHtml. Just in case you were wondering, it's now
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30417
diff changeset
793 cairo_destroy(cr);
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
794
10777
5a9df3199615 [gaim-migrate @ 12392]
Sean Egan <seanegan@pidgin.im>
parents: 10776
diff changeset
795 if (GTK_WIDGET_CLASS (parent_class)->expose_event)
5a9df3199615 [gaim-migrate @ 12392]
Sean Egan <seanegan@pidgin.im>
parents: 10776
diff changeset
796 return (* GTK_WIDGET_CLASS (parent_class)->expose_event)
5a9df3199615 [gaim-migrate @ 12392]
Sean Egan <seanegan@pidgin.im>
parents: 10776
diff changeset
797 (widget, event);
5a9df3199615 [gaim-migrate @ 12392]
Sean Egan <seanegan@pidgin.im>
parents: 10776
diff changeset
798 return FALSE;
5a9df3199615 [gaim-migrate @ 12392]
Sean Egan <seanegan@pidgin.im>
parents: 10776
diff changeset
799
5a9df3199615 [gaim-migrate @ 12392]
Sean Egan <seanegan@pidgin.im>
parents: 10776
diff changeset
800 }
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
801
10776
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
802 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(widget), &start, buf_x, buf_y);
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
803 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(widget), &end,
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
804 buf_x + event->area.width, buf_y + event->area.height);
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
805
23187
671e00775afb *** Plucked rev 69b22e32f7ada182101e0746f02891389ceb0c52 (sadrul@pidgin.im):
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23174
diff changeset
806 gtk_text_iter_order(&start, &end);
10776
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
807
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
808 cur = start;
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
809
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
810 while (gtk_text_iter_in_range(&cur, &start, &end)) {
10795
db5c480d8756 [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
811 GSList *tags = gtk_text_iter_get_tags(&cur);
db5c480d8756 [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
812 GSList *l;
10776
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
813
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
814 for (l = tags; l; l = l->next) {
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
815 GtkTextTag *tag = l->data;
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
816 GdkRectangle rect;
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
817 GdkRectangle tag_area;
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
818 const char *color;
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
819
10776
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
820 if (strncmp(tag->name, "BACKGROUND ", 11))
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
821 continue;
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
822
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
823 if (gtk_text_iter_ends_tag(&cur, tag))
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
824 continue;
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
825
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
826 gtk_text_view_get_iter_location(GTK_TEXT_VIEW(widget), &cur, &tag_area);
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
827 gtk_text_view_buffer_to_window_coords(GTK_TEXT_VIEW(widget),
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
828 GTK_TEXT_WINDOW_TEXT,
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
829 tag_area.x,
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
830 tag_area.y,
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
831 &tag_area.x,
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
832 &tag_area.y);
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
833 rect.x = visible_rect.x;
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
834 rect.y = tag_area.y;
11768
b45e26d7a4c9 [gaim-migrate @ 14059]
Gary Kramlich <grim@reaperworld.com>
parents: 11760
diff changeset
835 rect.width = visible_rect.width;
10776
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
836
10795
db5c480d8756 [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
837 do
10776
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
838 gtk_text_iter_forward_to_tag_toggle(&cur, tag);
10795
db5c480d8756 [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
839 while (!gtk_text_iter_is_end(&cur) && gtk_text_iter_begins_tag(&cur, tag));
db5c480d8756 [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
840
10776
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
841 gtk_text_view_get_iter_location(GTK_TEXT_VIEW(widget), &cur, &tag_area);
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
842 gtk_text_view_buffer_to_window_coords(GTK_TEXT_VIEW(widget),
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
843 GTK_TEXT_WINDOW_TEXT,
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
844 tag_area.x,
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
845 tag_area.y,
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
846 &tag_area.x,
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
847 &tag_area.y);
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
848
25888
d0fdd378a635 Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents: 25854
diff changeset
849
11760
075e1495157b [gaim-migrate @ 14051]
Sean Egan <seanegan@pidgin.im>
parents: 11750
diff changeset
850 rect.height = tag_area.y + tag_area.height - rect.y
22865
eeed3e121bed Move 2 of the 5 pixels' padding between paragraphs to above the line.
Will Thompson <resiak@pidgin.im>
parents: 22834
diff changeset
851 + gtk_text_view_get_pixels_above_lines(GTK_TEXT_VIEW(widget))
11760
075e1495157b [gaim-migrate @ 14051]
Sean Egan <seanegan@pidgin.im>
parents: 11750
diff changeset
852 + gtk_text_view_get_pixels_below_lines(GTK_TEXT_VIEW(widget));
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
853
10776
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
854 color = tag->name + 11;
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
855
10857
5efd8020695b [gaim-migrate @ 12533]
Tim Ringenbach <marv@pidgin.im>
parents: 10852
diff changeset
856 if (!gdk_color_parse(color, &gcolor)) {
10858
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
857 gchar tmp[8];
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
858 tmp[0] = '#';
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
859 strncpy(&tmp[1], color, 7);
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
860 tmp[7] = '\0';
10857
5efd8020695b [gaim-migrate @ 12533]
Tim Ringenbach <marv@pidgin.im>
parents: 10852
diff changeset
861 if (!gdk_color_parse(tmp, &gcolor))
5efd8020695b [gaim-migrate @ 12533]
Tim Ringenbach <marv@pidgin.im>
parents: 10852
diff changeset
862 gdk_color_parse("white", &gcolor);
5efd8020695b [gaim-migrate @ 12533]
Tim Ringenbach <marv@pidgin.im>
parents: 10852
diff changeset
863 }
30566
8263353b04de Replace GdkGC in GtkIMHtml. Just in case you were wondering, it's now
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30417
diff changeset
864 gdk_cairo_set_source_color(cr, &gcolor);
8263353b04de Replace GdkGC in GtkIMHtml. Just in case you were wondering, it's now
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30417
diff changeset
865
8263353b04de Replace GdkGC in GtkIMHtml. Just in case you were wondering, it's now
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30417
diff changeset
866 cairo_rectangle(cr,
8263353b04de Replace GdkGC in GtkIMHtml. Just in case you were wondering, it's now
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30417
diff changeset
867 rect.x, rect.y,
8263353b04de Replace GdkGC in GtkIMHtml. Just in case you were wondering, it's now
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30417
diff changeset
868 rect.width, rect.height);
8263353b04de Replace GdkGC in GtkIMHtml. Just in case you were wondering, it's now
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30417
diff changeset
869 cairo_fill(cr);
10795
db5c480d8756 [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
870 gtk_text_iter_backward_char(&cur); /* go back one, in case the end is the begining is the end
db5c480d8756 [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
871 * note that above, we always moved cur ahead by at least
db5c480d8756 [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
872 * one character */
10776
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
873 break;
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
874 }
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
875
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
876 g_slist_free(tags);
10795
db5c480d8756 [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
877
db5c480d8756 [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
878 /* loop until another tag begins, or no tag begins */
db5c480d8756 [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
879 while (gtk_text_iter_forward_to_tag_toggle(&cur, NULL) &&
db5c480d8756 [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
880 !gtk_text_iter_is_end(&cur) &&
db5c480d8756 [gaim-migrate @ 12438]
Tim Ringenbach <marv@pidgin.im>
parents: 10794
diff changeset
881 !gtk_text_iter_begins_tag(&cur, NULL));
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
882 }
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
883
30566
8263353b04de Replace GdkGC in GtkIMHtml. Just in case you were wondering, it's now
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30417
diff changeset
884 cairo_destroy(cr);
10777
5a9df3199615 [gaim-migrate @ 12392]
Sean Egan <seanegan@pidgin.im>
parents: 10776
diff changeset
885
10692
f5c8ae17800b [gaim-migrate @ 12243]
Sean Egan <seanegan@pidgin.im>
parents: 10666
diff changeset
886 if (GTK_WIDGET_CLASS (parent_class)->expose_event)
f5c8ae17800b [gaim-migrate @ 12243]
Sean Egan <seanegan@pidgin.im>
parents: 10666
diff changeset
887 return (* GTK_WIDGET_CLASS (parent_class)->expose_event)
f5c8ae17800b [gaim-migrate @ 12243]
Sean Egan <seanegan@pidgin.im>
parents: 10666
diff changeset
888 (widget, event);
10776
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
889
10692
f5c8ae17800b [gaim-migrate @ 12243]
Sean Egan <seanegan@pidgin.im>
parents: 10666
diff changeset
890 return FALSE;
f5c8ae17800b [gaim-migrate @ 12243]
Sean Egan <seanegan@pidgin.im>
parents: 10666
diff changeset
891 }
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
892 #endif
10692
f5c8ae17800b [gaim-migrate @ 12243]
Sean Egan <seanegan@pidgin.im>
parents: 10666
diff changeset
893
f5c8ae17800b [gaim-migrate @ 12243]
Sean Egan <seanegan@pidgin.im>
parents: 10666
diff changeset
894
8931
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
895 static void paste_unformatted_cb(GtkMenuItem *menu, GtkIMHtml *imhtml)
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
896 {
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
897 GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD);
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
898
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
899 gtk_clipboard_request_text(clipboard, paste_plaintext_received_cb, imhtml);
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
900
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
901 }
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
902
13336
e5ac6aad2723 [gaim-migrate @ 15705]
Nathan Walp <nwalp@pidgin.im>
parents: 13225
diff changeset
903 static void clear_formatting_cb(GtkMenuItem *menu, GtkIMHtml *imhtml)
e5ac6aad2723 [gaim-migrate @ 15705]
Nathan Walp <nwalp@pidgin.im>
parents: 13225
diff changeset
904 {
e5ac6aad2723 [gaim-migrate @ 15705]
Nathan Walp <nwalp@pidgin.im>
parents: 13225
diff changeset
905 gtk_imhtml_clear_formatting(imhtml);
e5ac6aad2723 [gaim-migrate @ 15705]
Nathan Walp <nwalp@pidgin.im>
parents: 13225
diff changeset
906 }
10692
f5c8ae17800b [gaim-migrate @ 12243]
Sean Egan <seanegan@pidgin.im>
parents: 10666
diff changeset
907
22970
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
908 static void disable_smiley_selected(GtkMenuItem *item, GtkIMHtml *imhtml)
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
909 {
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
910 GtkTextIter start, end;
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
911 GtkTextMark *mark;
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
912 char *text;
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
913
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
914 if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end))
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
915 return;
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
916
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
917 text = gtk_imhtml_get_markup_range(imhtml, &start, &end);
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
918
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
919 mark = gtk_text_buffer_get_selection_bound(imhtml->text_buffer);
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
920 gtk_text_buffer_delete_selection(imhtml->text_buffer, FALSE, FALSE);
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
921
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
922 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, mark);
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
923 gtk_imhtml_insert_html_at_iter(imhtml, text, GTK_IMHTML_NO_NEWLINE | GTK_IMHTML_NO_SMILEY, &start);
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
924
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
925 g_free(text);
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
926 }
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
927
8931
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
928 static void hijack_menu_cb(GtkIMHtml *imhtml, GtkMenu *menu, gpointer data)
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
929 {
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
930 GtkWidget *menuitem;
22970
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
931 GtkTextIter start, end;
8931
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
932
12635
5b2fbc3da55b [gaim-migrate @ 14971]
Richard Laager <rlaager@pidgin.im>
parents: 12605
diff changeset
933 menuitem = gtk_menu_item_new_with_mnemonic(_("Paste as Plain _Text"));
8931
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
934 gtk_widget_show(menuitem);
14970
fd8984ce4fda [gaim-migrate @ 17680]
Mark Doliner <markdoliner@pidgin.im>
parents: 14863
diff changeset
935 /*
fd8984ce4fda [gaim-migrate @ 17680]
Mark Doliner <markdoliner@pidgin.im>
parents: 14863
diff changeset
936 * TODO: gtk_clipboard_wait_is_text_available() iterates the glib
fd8984ce4fda [gaim-migrate @ 17680]
Mark Doliner <markdoliner@pidgin.im>
parents: 14863
diff changeset
937 * mainloop, which tends to be a source of bugs. It would
fd8984ce4fda [gaim-migrate @ 17680]
Mark Doliner <markdoliner@pidgin.im>
parents: 14863
diff changeset
938 * be good to audit this or change it to not wait.
fd8984ce4fda [gaim-migrate @ 17680]
Mark Doliner <markdoliner@pidgin.im>
parents: 14863
diff changeset
939 */
8931
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
940 gtk_widget_set_sensitive(menuitem,
12836
837fe5d43dac [gaim-migrate @ 15184]
Richard Laager <rlaager@pidgin.im>
parents: 12833
diff changeset
941 (imhtml->editable &&
837fe5d43dac [gaim-migrate @ 15184]
Richard Laager <rlaager@pidgin.im>
parents: 12833
diff changeset
942 gtk_clipboard_wait_is_text_available(
837fe5d43dac [gaim-migrate @ 15184]
Richard Laager <rlaager@pidgin.im>
parents: 12833
diff changeset
943 gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD))));
8931
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
944 /* put it after "Paste" */
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
945 gtk_menu_shell_insert(GTK_MENU_SHELL(menu), menuitem, 3);
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
946
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
947 g_signal_connect(G_OBJECT(menuitem), "activate",
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
948 G_CALLBACK(paste_unformatted_cb), imhtml);
13336
e5ac6aad2723 [gaim-migrate @ 15705]
Nathan Walp <nwalp@pidgin.im>
parents: 13225
diff changeset
949
13539
8036a635a316 [gaim-migrate @ 15915]
Richard Laager <rlaager@pidgin.im>
parents: 13340
diff changeset
950 menuitem = gtk_menu_item_new_with_mnemonic(_("_Reset formatting"));
13336
e5ac6aad2723 [gaim-migrate @ 15705]
Nathan Walp <nwalp@pidgin.im>
parents: 13225
diff changeset
951 gtk_widget_show(menuitem);
13340
e18166659513 [gaim-migrate @ 15709]
Richard Laager <rlaager@pidgin.im>
parents: 13336
diff changeset
952 gtk_widget_set_sensitive(menuitem, imhtml->editable);
13336
e5ac6aad2723 [gaim-migrate @ 15705]
Nathan Walp <nwalp@pidgin.im>
parents: 13225
diff changeset
953 /* put it after Delete */
e5ac6aad2723 [gaim-migrate @ 15705]
Nathan Walp <nwalp@pidgin.im>
parents: 13225
diff changeset
954 gtk_menu_shell_insert(GTK_MENU_SHELL(menu), menuitem, 5);
e5ac6aad2723 [gaim-migrate @ 15705]
Nathan Walp <nwalp@pidgin.im>
parents: 13225
diff changeset
955
e5ac6aad2723 [gaim-migrate @ 15705]
Nathan Walp <nwalp@pidgin.im>
parents: 13225
diff changeset
956 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(clear_formatting_cb), imhtml);
22970
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
957
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
958 menuitem = gtk_menu_item_new_with_mnemonic(_("Disable _smileys in selected text"));
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
959 gtk_widget_show(menuitem);
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
960 if (gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
961 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(disable_smiley_selected), imhtml);
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
962 } else {
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
963 gtk_widget_set_sensitive(menuitem, FALSE);
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
964 }
87aef86d20c5 Allow replacing smileys with texts in conversations/logs. This should be
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22865
diff changeset
965 gtk_menu_shell_insert(GTK_MENU_SHELL(menu), menuitem, 6);
8931
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
966 }
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
967
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
968 static char *
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
969 ucs2_order(gboolean swap)
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
970 {
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
971 gboolean be;
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
972
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
973 be = G_BYTE_ORDER == G_BIG_ENDIAN;
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
974 be = swap ? be : !be;
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
975
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
976 if (be)
22596
0854ae660ef4 Further changes to use UTF-16 instead of UCS-2. Also, fix #5167 by making sure that the encoding conversion worked before using the result.
Daniel Atallah <datallah@pidgin.im>
parents: 22595
diff changeset
977 return "UTF-16BE";
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
978 else
22596
0854ae660ef4 Further changes to use UTF-16 instead of UCS-2. Also, fix #5167 by making sure that the encoding conversion worked before using the result.
Daniel Atallah <datallah@pidgin.im>
parents: 22595
diff changeset
979 return "UTF-16LE";
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
980
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
981 }
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
982
22596
0854ae660ef4 Further changes to use UTF-16 instead of UCS-2. Also, fix #5167 by making sure that the encoding conversion worked before using the result.
Daniel Atallah <datallah@pidgin.im>
parents: 22595
diff changeset
983 /* Convert from UTF-16LE to UTF-8, stripping the BOM if one is present.*/
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
984 static gchar *
22596
0854ae660ef4 Further changes to use UTF-16 instead of UCS-2. Also, fix #5167 by making sure that the encoding conversion worked before using the result.
Daniel Atallah <datallah@pidgin.im>
parents: 22595
diff changeset
985 utf16_to_utf8_with_bom_check(gchar *data, guint len) {
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
986 char *fromcode = NULL;
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
987 GError *error = NULL;
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
988 guint16 c;
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
989 gchar *utf8_ret;
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
990
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
991 /*
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
992 * Unicode Techinical Report 20
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
993 * ( http://www.unicode.org/unicode/reports/tr20/ ) says to treat an
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
994 * initial 0xfeff (ZWNBSP) as a byte order indicator so that is
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
995 * what we do. If there is no indicator assume it is in the default
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
996 * order
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
997 */
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
998
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
999 memcpy(&c, data, 2);
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1000 switch (c) {
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1001 case 0xfeff:
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1002 case 0xfffe:
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1003 fromcode = ucs2_order(c == 0xfeff);
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1004 data += 2;
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1005 len -= 2;
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1006 break;
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1007 default:
22596
0854ae660ef4 Further changes to use UTF-16 instead of UCS-2. Also, fix #5167 by making sure that the encoding conversion worked before using the result.
Daniel Atallah <datallah@pidgin.im>
parents: 22595
diff changeset
1008 fromcode = "UTF-16";
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1009 break;
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1010 }
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1011
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1012 utf8_ret = g_convert(data, len, "UTF-8", fromcode, NULL, NULL, &error);
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1013
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1014 if (error) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15865
diff changeset
1015 purple_debug_warning("gtkimhtml", "g_convert error: %s\n", error->message);
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1016 g_error_free(error);
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1017 }
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1018 return utf8_ret;
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1019 }
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1020
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1021
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1022 static void gtk_imhtml_clipboard_get(GtkClipboard *clipboard, GtkSelectionData *selection_data, guint info, GtkIMHtml *imhtml) {
15111
e427dd6f3b7e [gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents: 15093
diff changeset
1023 char *text = NULL;
17546
51b1c1e2c3fe Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents: 17406
diff changeset
1024 gboolean primary = (clipboard != clipboard_selection);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1025 GtkTextIter start, end;
21085
dff5e0bfb8f5 Don't assign ownership of the CLIPBOARD to the IMHtml - it doesn't really own the data and then we don't have problems of overwriting what others put in the clipboard. Fixes #3616.
Daniel Atallah <datallah@pidgin.im>
parents: 21076
diff changeset
1026
dff5e0bfb8f5 Don't assign ownership of the CLIPBOARD to the IMHtml - it doesn't really own the data and then we don't have problems of overwriting what others put in the clipboard. Fixes #3616.
Daniel Atallah <datallah@pidgin.im>
parents: 21076
diff changeset
1027 if (primary) {
dff5e0bfb8f5 Don't assign ownership of the CLIPBOARD to the IMHtml - it doesn't really own the data and then we don't have problems of overwriting what others put in the clipboard. Fixes #3616.
Daniel Atallah <datallah@pidgin.im>
parents: 21076
diff changeset
1028 GtkTextMark *sel = NULL, *ins = NULL;
21643
4d1a61e30199 There appears to be a new GTK+ bug that causes the clipboard_clear callback to be triggered *after* the clipboard_copy callback on the second copy attempt. This makes stuff still work correctly when this happens (and, most importantly, not crash). I'll report this upstream.
Daniel Atallah <datallah@pidgin.im>
parents: 21574
diff changeset
1029
4d1a61e30199 There appears to be a new GTK+ bug that causes the clipboard_clear callback to be triggered *after* the clipboard_copy callback on the second copy attempt. This makes stuff still work correctly when this happens (and, most importantly, not crash). I'll report this upstream.
Daniel Atallah <datallah@pidgin.im>
parents: 21574
diff changeset
1030 g_return_if_fail(imhtml != NULL);
4d1a61e30199 There appears to be a new GTK+ bug that causes the clipboard_clear callback to be triggered *after* the clipboard_copy callback on the second copy attempt. This makes stuff still work correctly when this happens (and, most importantly, not crash). I'll report this upstream.
Daniel Atallah <datallah@pidgin.im>
parents: 21574
diff changeset
1031
17546
51b1c1e2c3fe Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents: 17406
diff changeset
1032 ins = gtk_text_buffer_get_insert(imhtml->text_buffer);
51b1c1e2c3fe Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents: 17406
diff changeset
1033 sel = gtk_text_buffer_get_selection_bound(imhtml->text_buffer);
51b1c1e2c3fe Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents: 17406
diff changeset
1034 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, sel);
51b1c1e2c3fe Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents: 17406
diff changeset
1035 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &end, ins);
51b1c1e2c3fe Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents: 17406
diff changeset
1036 }
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1037
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1038 if (info == TARGET_HTML) {
15111
e427dd6f3b7e [gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents: 15093
diff changeset
1039 char *selection;
e427dd6f3b7e [gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents: 15093
diff changeset
1040 #ifndef _WIN32
8907
17b9da22de1e [gaim-migrate @ 9677]
Gary Kramlich <grim@pidgin.im>
parents: 8890
diff changeset
1041 gsize len;
8681
f7dc7d2bf200 [gaim-migrate @ 9434]
Sean Egan <seanegan@pidgin.im>
parents: 8677
diff changeset
1042 if (primary) {
f7dc7d2bf200 [gaim-migrate @ 9434]
Sean Egan <seanegan@pidgin.im>
parents: 8677
diff changeset
1043 text = gtk_imhtml_get_markup_range(imhtml, &start, &end);
10013
6927760cd4fd [gaim-migrate @ 10930]
Gary Kramlich <grim@pidgin.im>
parents: 9924
diff changeset
1044 } else
17546
51b1c1e2c3fe Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents: 17406
diff changeset
1045 text = html_clipboard;
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1046
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1047 /* Mozilla asks that we start our text/html with the Unicode byte order mark */
23201
a9efe9add251 *** Plucked rev da43d671 (sadrul@pidgin.im):
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23187
diff changeset
1048 selection = g_convert(text, -1, "UTF-16", "UTF-8", NULL, &len, NULL);
11143
f606fb334190 [gaim-migrate @ 13207]
Mark Doliner <markdoliner@pidgin.im>
parents: 11069
diff changeset
1049 gtk_selection_data_set(selection_data, gdk_atom_intern("text/html", FALSE), 16, (const guchar *)selection, len);
15111
e427dd6f3b7e [gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents: 15093
diff changeset
1050 #else
18665
157820042a6f Fix #1727 and also plug a possible leak and make a little efficiency improvement to the win32 clipboard handling.
Daniel Atallah <datallah@pidgin.im>
parents: 18633
diff changeset
1051 selection = clipboard_html_to_win32(html_clipboard);
15111
e427dd6f3b7e [gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents: 15093
diff changeset
1052 gtk_selection_data_set(selection_data, gdk_atom_intern("HTML Format", FALSE), 8, (const guchar *)selection, strlen(selection));
e427dd6f3b7e [gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents: 15093
diff changeset
1053 #endif
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1054 g_free(selection);
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1055 } else {
8681
f7dc7d2bf200 [gaim-migrate @ 9434]
Sean Egan <seanegan@pidgin.im>
parents: 8677
diff changeset
1056 if (primary) {
f7dc7d2bf200 [gaim-migrate @ 9434]
Sean Egan <seanegan@pidgin.im>
parents: 8677
diff changeset
1057 text = gtk_imhtml_get_text(imhtml, &start, &end);
f7dc7d2bf200 [gaim-migrate @ 9434]
Sean Egan <seanegan@pidgin.im>
parents: 8677
diff changeset
1058 } else
17546
51b1c1e2c3fe Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents: 17406
diff changeset
1059 text = text_clipboard;
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1060 gtk_selection_data_set_text(selection_data, text, strlen(text));
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1061 }
8681
f7dc7d2bf200 [gaim-migrate @ 9434]
Sean Egan <seanegan@pidgin.im>
parents: 8677
diff changeset
1062 if (primary) /* This was allocated here */
f7dc7d2bf200 [gaim-migrate @ 9434]
Sean Egan <seanegan@pidgin.im>
parents: 8677
diff changeset
1063 g_free(text);
f7dc7d2bf200 [gaim-migrate @ 9434]
Sean Egan <seanegan@pidgin.im>
parents: 8677
diff changeset
1064 }
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1065
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1066 static void gtk_imhtml_primary_clipboard_clear(GtkClipboard *clipboard, GtkIMHtml *imhtml)
7749
afe790299bd7 [gaim-migrate @ 8394]
Sean Egan <seanegan@pidgin.im>
parents: 7745
diff changeset
1067 {
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1068 GtkTextIter insert;
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1069 GtkTextIter selection_bound;
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1070
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1071 gtk_text_buffer_get_iter_at_mark (imhtml->text_buffer, &insert,
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1072 gtk_text_buffer_get_mark (imhtml->text_buffer, "insert"));
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1073 gtk_text_buffer_get_iter_at_mark (imhtml->text_buffer, &selection_bound,
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1074 gtk_text_buffer_get_mark (imhtml->text_buffer, "selection_bound"));
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1075
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1076 if (!gtk_text_iter_equal (&insert, &selection_bound))
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1077 gtk_text_buffer_move_mark (imhtml->text_buffer,
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1078 gtk_text_buffer_get_mark (imhtml->text_buffer, "selection_bound"),
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1079 &insert);
7749
afe790299bd7 [gaim-migrate @ 8394]
Sean Egan <seanegan@pidgin.im>
parents: 7745
diff changeset
1080 }
7742
0289c206bcff [gaim-migrate @ 8387]
Sean Egan <seanegan@pidgin.im>
parents: 7740
diff changeset
1081
17546
51b1c1e2c3fe Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents: 17406
diff changeset
1082 static void gtk_imhtml_clipboard_clear (GtkClipboard *clipboard, GtkSelectionData *sel_data,
51b1c1e2c3fe Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents: 17406
diff changeset
1083 guint info, gpointer user_data_or_owner)
51b1c1e2c3fe Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents: 17406
diff changeset
1084 {
51b1c1e2c3fe Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents: 17406
diff changeset
1085 }
51b1c1e2c3fe Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents: 17406
diff changeset
1086
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1087 static void copy_clipboard_cb(GtkIMHtml *imhtml, gpointer unused)
7749
afe790299bd7 [gaim-migrate @ 8394]
Sean Egan <seanegan@pidgin.im>
parents: 7745
diff changeset
1088 {
8681
f7dc7d2bf200 [gaim-migrate @ 9434]
Sean Egan <seanegan@pidgin.im>
parents: 8677
diff changeset
1089 GtkTextIter start, end;
17288
ffda972c2fb4 Ignore copy/cut requests when there is no selection instead of clearing the clipboard. This is consistent with the rest of how GTK+ works. Fixes #1030
Daniel Atallah <datallah@pidgin.im>
parents: 17189
diff changeset
1090 if (gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
17546
51b1c1e2c3fe Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents: 17406
diff changeset
1091 if (!clipboard_selection)
51b1c1e2c3fe Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents: 17406
diff changeset
1092 clipboard_selection = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD);
21085
dff5e0bfb8f5 Don't assign ownership of the CLIPBOARD to the IMHtml - it doesn't really own the data and then we don't have problems of overwriting what others put in the clipboard. Fixes #3616.
Daniel Atallah <datallah@pidgin.im>
parents: 21076
diff changeset
1093 gtk_clipboard_set_with_data(clipboard_selection,
17288
ffda972c2fb4 Ignore copy/cut requests when there is no selection instead of clearing the clipboard. This is consistent with the rest of how GTK+ works. Fixes #1030
Daniel Atallah <datallah@pidgin.im>
parents: 17189
diff changeset
1094 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry),
ffda972c2fb4 Ignore copy/cut requests when there is no selection instead of clearing the clipboard. This is consistent with the rest of how GTK+ works. Fixes #1030
Daniel Atallah <datallah@pidgin.im>
parents: 17189
diff changeset
1095 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get,
21085
dff5e0bfb8f5 Don't assign ownership of the CLIPBOARD to the IMHtml - it doesn't really own the data and then we don't have problems of overwriting what others put in the clipboard. Fixes #3616.
Daniel Atallah <datallah@pidgin.im>
parents: 21076
diff changeset
1096 (GtkClipboardClearFunc)gtk_imhtml_clipboard_clear, NULL);
17288
ffda972c2fb4 Ignore copy/cut requests when there is no selection instead of clearing the clipboard. This is consistent with the rest of how GTK+ works. Fixes #1030
Daniel Atallah <datallah@pidgin.im>
parents: 17189
diff changeset
1097
18665
157820042a6f Fix #1727 and also plug a possible leak and make a little efficiency improvement to the win32 clipboard handling.
Daniel Atallah <datallah@pidgin.im>
parents: 18633
diff changeset
1098 g_free(html_clipboard);
157820042a6f Fix #1727 and also plug a possible leak and make a little efficiency improvement to the win32 clipboard handling.
Daniel Atallah <datallah@pidgin.im>
parents: 18633
diff changeset
1099 g_free(text_clipboard);
17288
ffda972c2fb4 Ignore copy/cut requests when there is no selection instead of clearing the clipboard. This is consistent with the rest of how GTK+ works. Fixes #1030
Daniel Atallah <datallah@pidgin.im>
parents: 17189
diff changeset
1100
21085
dff5e0bfb8f5 Don't assign ownership of the CLIPBOARD to the IMHtml - it doesn't really own the data and then we don't have problems of overwriting what others put in the clipboard. Fixes #3616.
Daniel Atallah <datallah@pidgin.im>
parents: 21076
diff changeset
1101 html_clipboard = gtk_imhtml_get_markup_range(imhtml, &start, &end);
dff5e0bfb8f5 Don't assign ownership of the CLIPBOARD to the IMHtml - it doesn't really own the data and then we don't have problems of overwriting what others put in the clipboard. Fixes #3616.
Daniel Atallah <datallah@pidgin.im>
parents: 21076
diff changeset
1102 text_clipboard = gtk_imhtml_get_text(imhtml, &start, &end);
8681
f7dc7d2bf200 [gaim-migrate @ 9434]
Sean Egan <seanegan@pidgin.im>
parents: 8677
diff changeset
1103 }
f7dc7d2bf200 [gaim-migrate @ 9434]
Sean Egan <seanegan@pidgin.im>
parents: 8677
diff changeset
1104
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1105 g_signal_stop_emission_by_name(imhtml, "copy-clipboard");
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1106 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1107
8698
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
1108 static void cut_clipboard_cb(GtkIMHtml *imhtml, gpointer unused)
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
1109 {
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
1110 GtkTextIter start, end;
17288
ffda972c2fb4 Ignore copy/cut requests when there is no selection instead of clearing the clipboard. This is consistent with the rest of how GTK+ works. Fixes #1030
Daniel Atallah <datallah@pidgin.im>
parents: 17189
diff changeset
1111 if (gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
17546
51b1c1e2c3fe Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents: 17406
diff changeset
1112 if (!clipboard_selection)
51b1c1e2c3fe Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents: 17406
diff changeset
1113 clipboard_selection = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD);
21085
dff5e0bfb8f5 Don't assign ownership of the CLIPBOARD to the IMHtml - it doesn't really own the data and then we don't have problems of overwriting what others put in the clipboard. Fixes #3616.
Daniel Atallah <datallah@pidgin.im>
parents: 21076
diff changeset
1114 gtk_clipboard_set_with_data(clipboard_selection,
17288
ffda972c2fb4 Ignore copy/cut requests when there is no selection instead of clearing the clipboard. This is consistent with the rest of how GTK+ works. Fixes #1030
Daniel Atallah <datallah@pidgin.im>
parents: 17189
diff changeset
1115 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry),
ffda972c2fb4 Ignore copy/cut requests when there is no selection instead of clearing the clipboard. This is consistent with the rest of how GTK+ works. Fixes #1030
Daniel Atallah <datallah@pidgin.im>
parents: 17189
diff changeset
1116 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get,
21085
dff5e0bfb8f5 Don't assign ownership of the CLIPBOARD to the IMHtml - it doesn't really own the data and then we don't have problems of overwriting what others put in the clipboard. Fixes #3616.
Daniel Atallah <datallah@pidgin.im>
parents: 21076
diff changeset
1117 (GtkClipboardClearFunc)gtk_imhtml_clipboard_clear, NULL);
17288
ffda972c2fb4 Ignore copy/cut requests when there is no selection instead of clearing the clipboard. This is consistent with the rest of how GTK+ works. Fixes #1030
Daniel Atallah <datallah@pidgin.im>
parents: 17189
diff changeset
1118
18665
157820042a6f Fix #1727 and also plug a possible leak and make a little efficiency improvement to the win32 clipboard handling.
Daniel Atallah <datallah@pidgin.im>
parents: 18633
diff changeset
1119 g_free(html_clipboard);
157820042a6f Fix #1727 and also plug a possible leak and make a little efficiency improvement to the win32 clipboard handling.
Daniel Atallah <datallah@pidgin.im>
parents: 18633
diff changeset
1120 g_free(text_clipboard);
17288
ffda972c2fb4 Ignore copy/cut requests when there is no selection instead of clearing the clipboard. This is consistent with the rest of how GTK+ works. Fixes #1030
Daniel Atallah <datallah@pidgin.im>
parents: 17189
diff changeset
1121
21085
dff5e0bfb8f5 Don't assign ownership of the CLIPBOARD to the IMHtml - it doesn't really own the data and then we don't have problems of overwriting what others put in the clipboard. Fixes #3616.
Daniel Atallah <datallah@pidgin.im>
parents: 21076
diff changeset
1122 html_clipboard = gtk_imhtml_get_markup_range(imhtml, &start, &end);
dff5e0bfb8f5 Don't assign ownership of the CLIPBOARD to the IMHtml - it doesn't really own the data and then we don't have problems of overwriting what others put in the clipboard. Fixes #3616.
Daniel Atallah <datallah@pidgin.im>
parents: 21076
diff changeset
1123 text_clipboard = gtk_imhtml_get_text(imhtml, &start, &end);
17546
51b1c1e2c3fe Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents: 17406
diff changeset
1124
17288
ffda972c2fb4 Ignore copy/cut requests when there is no selection instead of clearing the clipboard. This is consistent with the rest of how GTK+ works. Fixes #1030
Daniel Atallah <datallah@pidgin.im>
parents: 17189
diff changeset
1125 if (imhtml->editable)
ffda972c2fb4 Ignore copy/cut requests when there is no selection instead of clearing the clipboard. This is consistent with the rest of how GTK+ works. Fixes #1030
Daniel Atallah <datallah@pidgin.im>
parents: 17189
diff changeset
1126 gtk_text_buffer_delete_selection(imhtml->text_buffer, FALSE, FALSE);
8698
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
1127 }
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
1128
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
1129 g_signal_stop_emission_by_name(imhtml, "cut-clipboard");
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
1130 }
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
1131
8931
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1132 static void imhtml_paste_insert(GtkIMHtml *imhtml, const char *text, gboolean plaintext)
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1133 {
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1134 GtkTextIter iter;
22003
904ebe8d6058 Patch from 'goutnet' to not insert smileys when pasting as plain text.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21765
diff changeset
1135 GtkIMHtmlOptions flags = plaintext ? GTK_IMHTML_NO_SMILEY : (GTK_IMHTML_NO_NEWLINE | GTK_IMHTML_NO_COMMENTS);
8931
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1136
25899
da25a7ed382e The first thing gtk_text_buffer_delete_selection does is call
Mark Doliner <markdoliner@pidgin.im>
parents: 25888
diff changeset
1137 /* Delete any currently selected text */
da25a7ed382e The first thing gtk_text_buffer_delete_selection does is call
Mark Doliner <markdoliner@pidgin.im>
parents: 25888
diff changeset
1138 gtk_text_buffer_delete_selection(imhtml->text_buffer, TRUE, TRUE);
9028
9a1a32485442 [gaim-migrate @ 9804]
Tim Ringenbach <marv@pidgin.im>
parents: 9025
diff changeset
1139
8931
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1140 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, gtk_text_buffer_get_insert(imhtml->text_buffer));
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1141 if (!imhtml->wbfo && !plaintext)
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1142 gtk_imhtml_close_tags(imhtml, &iter);
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1143
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1144 gtk_imhtml_insert_html_at_iter(imhtml, text, flags, &iter);
11267
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
1145 gtk_text_buffer_move_mark_by_name(imhtml->text_buffer, "insert", &iter);
8931
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1146 gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(imhtml), gtk_text_buffer_get_insert(imhtml->text_buffer),
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1147 0, FALSE, 0.0, 0.0);
18363
3e2a0ab4d6f8 Re-arrange a few lines in gtkimhtml's paste function so that we reset formatting after moving the cursor to the new location. Fixes #1198
Sean Egan <seanegan@pidgin.im>
parents: 18283
diff changeset
1148 if (!imhtml->wbfo && !plaintext)
3e2a0ab4d6f8 Re-arrange a few lines in gtkimhtml's paste function so that we reset formatting after moving the cursor to the new location. Fixes #1198
Sean Egan <seanegan@pidgin.im>
parents: 18283
diff changeset
1149 gtk_imhtml_close_tags(imhtml, &iter);
3e2a0ab4d6f8 Re-arrange a few lines in gtkimhtml's paste function so that we reset formatting after moving the cursor to the new location. Fixes #1198
Sean Egan <seanegan@pidgin.im>
parents: 18283
diff changeset
1150
8931
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1151 }
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1152
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1153 static void paste_plaintext_received_cb (GtkClipboard *clipboard, const gchar *text, gpointer data)
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1154 {
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1155 char *tmp;
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1156
19332
06b251c98872 malloc(0) returns a null pointer. Fixes #2472.
Daniel Atallah <datallah@pidgin.im>
parents: 19103
diff changeset
1157 if (text == NULL || !(*text))
8931
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1158 return;
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1159
10732
5e314ab498bf [gaim-migrate @ 12334]
Richard Laager <rlaager@pidgin.im>
parents: 10699
diff changeset
1160 tmp = g_markup_escape_text(text, -1);
8931
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1161 imhtml_paste_insert(data, tmp, TRUE);
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1162 g_free(tmp);
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1163 }
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1164
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1165 static void paste_received_cb (GtkClipboard *clipboard, GtkSelectionData *selection_data, gpointer data)
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1166 {
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1167 char *text;
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1168 GtkIMHtml *imhtml = data;
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
1169 gint length = gtk_selection_data_get_length(selection_data);
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
1170
8123
e09c75f511c2 [gaim-migrate @ 8827]
Mark Doliner <markdoliner@pidgin.im>
parents: 8120
diff changeset
1171 if (!gtk_text_view_get_editable(GTK_TEXT_VIEW(imhtml)))
8105
54ea897b764e [gaim-migrate @ 8805]
Nathan Fredrickson <nathan@silverorange.com>
parents: 8091
diff changeset
1172 return;
54ea897b764e [gaim-migrate @ 8805]
Nathan Fredrickson <nathan@silverorange.com>
parents: 8091
diff changeset
1173
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1174 if (imhtml->wbfo || length <= 0) {
8931
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1175 gtk_clipboard_request_text(clipboard, paste_plaintext_received_cb, imhtml);
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1176 return;
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1177 } else {
8719
1d1a4e11b4ab [gaim-migrate @ 9474]
Tim Ringenbach <marv@pidgin.im>
parents: 8707
diff changeset
1178 #if 0
1d1a4e11b4ab [gaim-migrate @ 9474]
Tim Ringenbach <marv@pidgin.im>
parents: 8707
diff changeset
1179 /* Here's some debug code, for figuring out what sent to us over the clipboard. */
1d1a4e11b4ab [gaim-migrate @ 9474]
Tim Ringenbach <marv@pidgin.im>
parents: 8707
diff changeset
1180 {
1d1a4e11b4ab [gaim-migrate @ 9474]
Tim Ringenbach <marv@pidgin.im>
parents: 8707
diff changeset
1181 int i;
1d1a4e11b4ab [gaim-migrate @ 9474]
Tim Ringenbach <marv@pidgin.im>
parents: 8707
diff changeset
1182
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15865
diff changeset
1183 purple_debug_misc("gtkimhtml", "In paste_received_cb():\n\tformat = %d, length = %d\n\t",
8719
1d1a4e11b4ab [gaim-migrate @ 9474]
Tim Ringenbach <marv@pidgin.im>
parents: 8707
diff changeset
1184 selection_data->format, selection_data->length);
1d1a4e11b4ab [gaim-migrate @ 9474]
Tim Ringenbach <marv@pidgin.im>
parents: 8707
diff changeset
1185
1d1a4e11b4ab [gaim-migrate @ 9474]
Tim Ringenbach <marv@pidgin.im>
parents: 8707
diff changeset
1186 for (i = 0; i < (/*(selection_data->format / 8) **/ selection_data->length); i++) {
1d1a4e11b4ab [gaim-migrate @ 9474]
Tim Ringenbach <marv@pidgin.im>
parents: 8707
diff changeset
1187 if ((i % 70) == 0)
1d1a4e11b4ab [gaim-migrate @ 9474]
Tim Ringenbach <marv@pidgin.im>
parents: 8707
diff changeset
1188 printf("\n\t");
1d1a4e11b4ab [gaim-migrate @ 9474]
Tim Ringenbach <marv@pidgin.im>
parents: 8707
diff changeset
1189 if (selection_data->data[i] == '\0')
1d1a4e11b4ab [gaim-migrate @ 9474]
Tim Ringenbach <marv@pidgin.im>
parents: 8707
diff changeset
1190 printf(".");
1d1a4e11b4ab [gaim-migrate @ 9474]
Tim Ringenbach <marv@pidgin.im>
parents: 8707
diff changeset
1191 else
1d1a4e11b4ab [gaim-migrate @ 9474]
Tim Ringenbach <marv@pidgin.im>
parents: 8707
diff changeset
1192 printf("%c", selection_data->data[i]);
1d1a4e11b4ab [gaim-migrate @ 9474]
Tim Ringenbach <marv@pidgin.im>
parents: 8707
diff changeset
1193 }
1d1a4e11b4ab [gaim-migrate @ 9474]
Tim Ringenbach <marv@pidgin.im>
parents: 8707
diff changeset
1194 printf("\n");
1d1a4e11b4ab [gaim-migrate @ 9474]
Tim Ringenbach <marv@pidgin.im>
parents: 8707
diff changeset
1195 }
1d1a4e11b4ab [gaim-migrate @ 9474]
Tim Ringenbach <marv@pidgin.im>
parents: 8707
diff changeset
1196 #endif
30033
391b14824468 gtkimhtml: Fix handling of pastes whose data isn't NULL-terminated
Paul Aurich <darkrain42@pidgin.im>
parents: 29909
diff changeset
1197
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1198 text = g_malloc(length + 1);
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1199 memcpy(text, gtk_selection_data_get_data(selection_data), length);
30033
391b14824468 gtkimhtml: Fix handling of pastes whose data isn't NULL-terminated
Paul Aurich <darkrain42@pidgin.im>
parents: 29909
diff changeset
1200 /* Make sure the paste data is null-terminated. Given that
30034
813bbed196d7 Clarify
Paul Aurich <darkrain42@pidgin.im>
parents: 30033
diff changeset
1201 * we're passed length (but assume later that it is
813bbed196d7 Clarify
Paul Aurich <darkrain42@pidgin.im>
parents: 30033
diff changeset
1202 * null-terminated), this seems sensible to me.
30033
391b14824468 gtkimhtml: Fix handling of pastes whose data isn't NULL-terminated
Paul Aurich <darkrain42@pidgin.im>
parents: 29909
diff changeset
1203 */
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1204 text[length] = '\0';
7766
7d7115c189d7 [gaim-migrate @ 8411]
Sean Egan <seanegan@pidgin.im>
parents: 7754
diff changeset
1205 }
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1206
29855
234f74a60570 I think this works around the problem with the Win32 Clipboard and GTK+ 2.16.
Daniel Atallah <datallah@pidgin.im>
parents: 29724
diff changeset
1207 #ifdef _WIN32
234f74a60570 I think this works around the problem with the Win32 Clipboard and GTK+ 2.16.
Daniel Atallah <datallah@pidgin.im>
parents: 29724
diff changeset
1208 if (gtk_selection_data_get_data_type(selection_data) == gdk_atom_intern("HTML Format", FALSE)) {
234f74a60570 I think this works around the problem with the Win32 Clipboard and GTK+ 2.16.
Daniel Atallah <datallah@pidgin.im>
parents: 29724
diff changeset
1209 char *tmp = clipboard_win32_to_html(text);
234f74a60570 I think this works around the problem with the Win32 Clipboard and GTK+ 2.16.
Daniel Atallah <datallah@pidgin.im>
parents: 29724
diff changeset
1210 g_free(text);
234f74a60570 I think this works around the problem with the Win32 Clipboard and GTK+ 2.16.
Daniel Atallah <datallah@pidgin.im>
parents: 29724
diff changeset
1211 text = tmp;
234f74a60570 I think this works around the problem with the Win32 Clipboard and GTK+ 2.16.
Daniel Atallah <datallah@pidgin.im>
parents: 29724
diff changeset
1212 }
234f74a60570 I think this works around the problem with the Win32 Clipboard and GTK+ 2.16.
Daniel Atallah <datallah@pidgin.im>
parents: 29724
diff changeset
1213 #endif
234f74a60570 I think this works around the problem with the Win32 Clipboard and GTK+ 2.16.
Daniel Atallah <datallah@pidgin.im>
parents: 29724
diff changeset
1214
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1215 if (length >= 2 &&
8869
19ba5ea87889 [gaim-migrate @ 9637]
Ethan Blanton <elb@pidgin.im>
parents: 8858
diff changeset
1216 (*(guint16 *)text == 0xfeff || *(guint16 *)text == 0xfffe)) {
22596
0854ae660ef4 Further changes to use UTF-16 instead of UCS-2. Also, fix #5167 by making sure that the encoding conversion worked before using the result.
Daniel Atallah <datallah@pidgin.im>
parents: 22595
diff changeset
1217 /* This is UTF-16 */
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1218 char *utf8 = utf16_to_utf8_with_bom_check(text, length);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1219 g_free(text);
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1220 text = utf8;
8698
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
1221 if (!text) {
22596
0854ae660ef4 Further changes to use UTF-16 instead of UCS-2. Also, fix #5167 by making sure that the encoding conversion worked before using the result.
Daniel Atallah <datallah@pidgin.im>
parents: 22595
diff changeset
1222 purple_debug_warning("gtkimhtml", "g_convert from UTF-16 failed in paste_received_cb\n");
8698
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
1223 return;
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
1224 }
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1225 }
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1226
8698
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
1227 if (!(*text) || !g_utf8_validate(text, -1, NULL)) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15865
diff changeset
1228 purple_debug_warning("gtkimhtml", "empty string or invalid UTF-8 in paste_received_cb\n");
8698
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
1229 g_free(text);
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
1230 return;
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
1231 }
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
1232
8931
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1233 imhtml_paste_insert(imhtml, text, FALSE);
8681
f7dc7d2bf200 [gaim-migrate @ 9434]
Sean Egan <seanegan@pidgin.im>
parents: 8677
diff changeset
1234 g_free(text);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1235 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1236
21765
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1237
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1238 static void smart_backspace_cb(GtkIMHtml *imhtml, gpointer blah)
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1239 {
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1240 GtkTextIter iter;
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1241 GtkTextChildAnchor* anchor;
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1242 char * text;
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1243 gint offset;
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1244
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1245 if (!imhtml->editable)
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1246 return;
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1247
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1248 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, gtk_text_buffer_get_insert(imhtml->text_buffer));
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1249
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1250 /* Get the character before the insertion point */
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1251 offset = gtk_text_iter_get_offset(&iter);
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1252 if (offset <= 0)
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1253 return;
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1254
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1255 gtk_text_iter_backward_char(&iter);
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1256 anchor = gtk_text_iter_get_child_anchor(&iter);
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1257
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1258 if (!anchor)
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1259 return; /* No smiley here */
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1260
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1261 text = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_plaintext");
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1262 if (!text)
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1263 return;
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1264
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1265 /* ok, then we need to insert the image buffer text before the anchor */
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1266 gtk_text_buffer_insert(imhtml->text_buffer, &iter, text, -1);
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1267 }
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
1268
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1269 static void paste_clipboard_cb(GtkIMHtml *imhtml, gpointer blah)
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1270 {
8931
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1271 #ifdef _WIN32
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1272 /* If we're on windows, let's see if we can get data from the HTML Format
10901
5d81e32bd258 [gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents: 10900
diff changeset
1273 clipboard before we try to paste from the GTK buffer */
30264
9fd897f50d8c Prevent pasting into readonly imhtmls on Windows. Fixes #11867
Daniel Atallah <datallah@pidgin.im>
parents: 30034
diff changeset
1274 if (!clipboard_paste_html_win32(imhtml) && gtk_text_view_get_editable(GTK_TEXT_VIEW(imhtml))) {
29855
234f74a60570 I think this works around the problem with the Win32 Clipboard and GTK+ 2.16.
Daniel Atallah <datallah@pidgin.im>
parents: 29724
diff changeset
1275 GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD);
234f74a60570 I think this works around the problem with the Win32 Clipboard and GTK+ 2.16.
Daniel Atallah <datallah@pidgin.im>
parents: 29724
diff changeset
1276 gtk_clipboard_request_text(clipboard, paste_plaintext_received_cb, imhtml);
234f74a60570 I think this works around the problem with the Win32 Clipboard and GTK+ 2.16.
Daniel Atallah <datallah@pidgin.im>
parents: 29724
diff changeset
1277
234f74a60570 I think this works around the problem with the Win32 Clipboard and GTK+ 2.16.
Daniel Atallah <datallah@pidgin.im>
parents: 29724
diff changeset
1278 }
234f74a60570 I think this works around the problem with the Win32 Clipboard and GTK+ 2.16.
Daniel Atallah <datallah@pidgin.im>
parents: 29724
diff changeset
1279 #else
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1280 GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD);
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1281 gtk_clipboard_request_contents(clipboard, gdk_atom_intern("text/html", FALSE),
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1282 paste_received_cb, imhtml);
29855
234f74a60570 I think this works around the problem with the Win32 Clipboard and GTK+ 2.16.
Daniel Atallah <datallah@pidgin.im>
parents: 29724
diff changeset
1283 #endif
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1284 g_signal_stop_emission_by_name(imhtml, "paste-clipboard");
7766
7d7115c189d7 [gaim-migrate @ 8411]
Sean Egan <seanegan@pidgin.im>
parents: 7754
diff changeset
1285 }
7d7115c189d7 [gaim-migrate @ 8411]
Sean Egan <seanegan@pidgin.im>
parents: 7754
diff changeset
1286
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1287 static void imhtml_realized_remove_primary(GtkIMHtml *imhtml, gpointer unused)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1288 {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1289 gtk_text_buffer_remove_selection_clipboard(GTK_IMHTML(imhtml)->text_buffer,
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1290 gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY));
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1291
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1292 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1293
8740
098a43943bba [gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents: 8735
diff changeset
1294 static void imhtml_destroy_add_primary(GtkIMHtml *imhtml, gpointer unused)
098a43943bba [gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents: 8735
diff changeset
1295 {
098a43943bba [gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents: 8735
diff changeset
1296 gtk_text_buffer_add_selection_clipboard(GTK_IMHTML(imhtml)->text_buffer,
098a43943bba [gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents: 8735
diff changeset
1297 gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY));
098a43943bba [gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents: 8735
diff changeset
1298 }
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1299
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1300 static void mark_set_so_update_selection_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, GtkIMHtml *imhtml)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1301 {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1302 if (gtk_text_buffer_get_selection_bounds(buffer, NULL, NULL)) {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1303 gtk_clipboard_set_with_owner(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY),
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1304 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry),
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1305 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get,
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1306 (GtkClipboardClearFunc)gtk_imhtml_primary_clipboard_clear, G_OBJECT(imhtml));
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1307 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1308 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1309
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1310 static gboolean gtk_imhtml_button_press_event(GtkIMHtml *imhtml, GdkEventButton *event, gpointer unused)
7346
7a2bc2fa15bc [gaim-migrate @ 7937]
Sean Egan <seanegan@pidgin.im>
parents: 7344
diff changeset
1311 {
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1312 if (event->button == 2) {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1313 int x, y;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1314 GtkTextIter iter;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1315 GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1316
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1317 if (!imhtml->editable)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1318 return FALSE;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1319
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1320 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(imhtml),
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1321 GTK_TEXT_WINDOW_TEXT,
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1322 event->x,
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1323 event->y,
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1324 &x,
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1325 &y);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1326 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, x, y);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1327 gtk_text_buffer_place_cursor(imhtml->text_buffer, &iter);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1328
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1329 gtk_clipboard_request_contents(clipboard, gdk_atom_intern("text/html", FALSE),
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1330 paste_received_cb, imhtml);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1331
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1332 return TRUE;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1333 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1334
7346
7a2bc2fa15bc [gaim-migrate @ 7937]
Sean Egan <seanegan@pidgin.im>
parents: 7344
diff changeset
1335 return FALSE;
7a2bc2fa15bc [gaim-migrate @ 7937]
Sean Egan <seanegan@pidgin.im>
parents: 7344
diff changeset
1336 }
4263
054b3ea4e7c5 [gaim-migrate @ 4514]
Sean Egan <seanegan@pidgin.im>
parents: 4253
diff changeset
1337
17880
5e73968467e0 Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents: 17288
diff changeset
1338 static void
22834
1394e7efb818 Smiley insertions can be undone with this fix. References #5577. But redo
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22810
diff changeset
1339 gtk_imhtml_undo(GtkIMHtml *imhtml)
1394e7efb818 Smiley insertions can be undone with this fix. References #5577. But redo
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22810
diff changeset
1340 {
17880
5e73968467e0 Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents: 17288
diff changeset
1341 g_return_if_fail(GTK_IS_IMHTML(imhtml));
22834
1394e7efb818 Smiley insertions can be undone with this fix. References #5577. But redo
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22810
diff changeset
1342 if (imhtml->editable &&
1394e7efb818 Smiley insertions can be undone with this fix. References #5577. But redo
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22810
diff changeset
1343 gtk_source_undo_manager_can_undo(imhtml->undo_manager))
21574
b27c242d1288 Fix #3930 by correctly detecting when we're no longer immediately following a br.
Daniel Atallah <datallah@pidgin.im>
parents: 21425
diff changeset
1344 gtk_source_undo_manager_undo(imhtml->undo_manager);
17880
5e73968467e0 Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents: 17288
diff changeset
1345 }
5e73968467e0 Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents: 17288
diff changeset
1346
5e73968467e0 Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents: 17288
diff changeset
1347 static void
22834
1394e7efb818 Smiley insertions can be undone with this fix. References #5577. But redo
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22810
diff changeset
1348 gtk_imhtml_redo(GtkIMHtml *imhtml)
1394e7efb818 Smiley insertions can be undone with this fix. References #5577. But redo
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22810
diff changeset
1349 {
17880
5e73968467e0 Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents: 17288
diff changeset
1350 g_return_if_fail(GTK_IS_IMHTML(imhtml));
22834
1394e7efb818 Smiley insertions can be undone with this fix. References #5577. But redo
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22810
diff changeset
1351 if (imhtml->editable &&
1394e7efb818 Smiley insertions can be undone with this fix. References #5577. But redo
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22810
diff changeset
1352 gtk_source_undo_manager_can_redo(imhtml->undo_manager))
21574
b27c242d1288 Fix #3930 by correctly detecting when we're no longer immediately following a br.
Daniel Atallah <datallah@pidgin.im>
parents: 21425
diff changeset
1353 gtk_source_undo_manager_redo(imhtml->undo_manager);
17880
5e73968467e0 Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents: 17288
diff changeset
1354
5e73968467e0 Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents: 17288
diff changeset
1355 }
5e73968467e0 Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents: 17288
diff changeset
1356
10108
0897c42d6cb9 [gaim-migrate @ 11141]
Sean Egan <seanegan@pidgin.im>
parents: 10100
diff changeset
1357 static gboolean imhtml_message_send(GtkIMHtml *imhtml)
0897c42d6cb9 [gaim-migrate @ 11141]
Sean Egan <seanegan@pidgin.im>
parents: 10100
diff changeset
1358 {
0897c42d6cb9 [gaim-migrate @ 11141]
Sean Egan <seanegan@pidgin.im>
parents: 10100
diff changeset
1359 return FALSE;
0897c42d6cb9 [gaim-migrate @ 11141]
Sean Egan <seanegan@pidgin.im>
parents: 10100
diff changeset
1360 }
0897c42d6cb9 [gaim-migrate @ 11141]
Sean Egan <seanegan@pidgin.im>
parents: 10100
diff changeset
1361
29909
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1362 static void
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1363 imhtml_paste_cb(GtkIMHtml *imhtml, const char *str)
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1364 {
30417
ee5cccb21cc7 Do not paste in a read-only imhtml. Fixes #12109.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 30264
diff changeset
1365 if (!gtk_text_view_get_editable(GTK_TEXT_VIEW(imhtml)))
ee5cccb21cc7 Do not paste in a read-only imhtml. Fixes #12109.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 30264
diff changeset
1366 return;
ee5cccb21cc7 Do not paste in a read-only imhtml. Fixes #12109.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 30264
diff changeset
1367
29909
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1368 if (!str || !*str || !strcmp(str, "html"))
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1369 g_signal_emit_by_name(imhtml, "paste_clipboard");
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1370 else if (!strcmp(str, "text"))
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1371 paste_unformatted_cb(NULL, imhtml);
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1372 }
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1373
10100
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1374 static void imhtml_toggle_format(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons)
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1375 {
10699
7f9fa4f13758 [gaim-migrate @ 12256]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10695
diff changeset
1376 /* since this function is the handler for the formatting keystrokes,
7f9fa4f13758 [gaim-migrate @ 12256]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10695
diff changeset
1377 we need to check here that the formatting attempted is permitted */
11275
cdcc651d7ecd [gaim-migrate @ 13461]
Richard Laager <rlaager@pidgin.im>
parents: 11269
diff changeset
1378 buttons &= imhtml->format_functions;
10699
7f9fa4f13758 [gaim-migrate @ 12256]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10695
diff changeset
1379
10100
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1380 switch (buttons) {
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1381 case GTK_IMHTML_BOLD:
11267
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
1382 imhtml_toggle_bold(imhtml);
10100
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1383 break;
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1384 case GTK_IMHTML_ITALIC:
11267
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
1385 imhtml_toggle_italic(imhtml);
10100
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1386 break;
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1387 case GTK_IMHTML_UNDERLINE:
11267
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
1388 imhtml_toggle_underline(imhtml);
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
1389 break;
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
1390 case GTK_IMHTML_STRIKE:
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
1391 imhtml_toggle_strike(imhtml);
10100
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1392 break;
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1393 case GTK_IMHTML_SHRINK:
11267
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
1394 imhtml_font_shrink(imhtml);
10100
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1395 break;
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1396 case GTK_IMHTML_GROW:
11267
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
1397 imhtml_font_grow(imhtml);
10100
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1398 break;
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1399 default:
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1400 break;
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1401 }
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1402 }
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
1403
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
1404 static void
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
1405 gtk_imhtml_finalize (GObject *object)
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
1406 {
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
1407 GtkIMHtml *imhtml = GTK_IMHTML(object);
4895
51794f61995e [gaim-migrate @ 5227]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4892
diff changeset
1408 GList *scalables;
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
1409 GSList *l;
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1410
10798
d1aae5d8adb2 [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
1411 if (imhtml->scroll_src)
d1aae5d8adb2 [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
1412 g_source_remove(imhtml->scroll_src);
d1aae5d8adb2 [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
1413 if (imhtml->scroll_time)
d1aae5d8adb2 [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
1414 g_timer_destroy(imhtml->scroll_time);
d1aae5d8adb2 [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
1415
4138
727cb2d2b93c [gaim-migrate @ 4356]
Ari Pollak <ari@debian.org>
parents: 4046
diff changeset
1416 g_hash_table_destroy(imhtml->smiley_data);
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
1417 gtk_smiley_tree_destroy(imhtml->default_smilies);
4138
727cb2d2b93c [gaim-migrate @ 4356]
Ari Pollak <ari@debian.org>
parents: 4046
diff changeset
1418 gdk_cursor_unref(imhtml->hand_cursor);
727cb2d2b93c [gaim-migrate @ 4356]
Ari Pollak <ari@debian.org>
parents: 4046
diff changeset
1419 gdk_cursor_unref(imhtml->arrow_cursor);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1420 gdk_cursor_unref(imhtml->text_cursor);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1421
4735
ac5f2489f6ee [gaim-migrate @ 5050]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4635
diff changeset
1422 if(imhtml->tip_window){
ac5f2489f6ee [gaim-migrate @ 5050]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4635
diff changeset
1423 gtk_widget_destroy(imhtml->tip_window);
ac5f2489f6ee [gaim-migrate @ 5050]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4635
diff changeset
1424 }
ac5f2489f6ee [gaim-migrate @ 5050]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4635
diff changeset
1425 if(imhtml->tip_timer)
26829
ac9a76ef6ef0 Replace gtk_timeout_remove with g_source_remove.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26828
diff changeset
1426 g_source_remove(imhtml->tip_timer);
4735
ac5f2489f6ee [gaim-migrate @ 5050]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4635
diff changeset
1427
4895
51794f61995e [gaim-migrate @ 5227]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4892
diff changeset
1428 for(scalables = imhtml->scalables; scalables; scalables = scalables->next) {
11224
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
1429 struct scalable_data *sd = scalables->data;
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
1430 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(sd->scalable);
4895
51794f61995e [gaim-migrate @ 5227]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4892
diff changeset
1431 scale->free(scale);
11224
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
1432 g_free(sd);
4895
51794f61995e [gaim-migrate @ 5227]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4892
diff changeset
1433 }
7991
845539e84417 [gaim-migrate @ 8668]
Ka-Hing Cheung <khc@pidgin.im>
parents: 7988
diff changeset
1434
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
1435 for (l = imhtml->im_images; l; l = l->next) {
11224
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
1436 struct im_image_data *img_data = l->data;
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
1437 if (imhtml->funcs->image_unref)
11224
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
1438 imhtml->funcs->image_unref(img_data->id);
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
1439 g_free(img_data);
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
1440 }
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
1441
4895
51794f61995e [gaim-migrate @ 5227]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4892
diff changeset
1442 g_list_free(imhtml->scalables);
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
1443 g_slist_free(imhtml->im_images);
16385
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
1444 g_queue_free(imhtml->animations);
14097
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 14010
diff changeset
1445 g_free(imhtml->protocol_name);
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 14010
diff changeset
1446 g_free(imhtml->search_string);
17880
5e73968467e0 Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents: 17288
diff changeset
1447 g_object_unref(imhtml->undo_manager);
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
1448 G_OBJECT_CLASS(parent_class)->finalize (object);
17546
51b1c1e2c3fe Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents: 17406
diff changeset
1449
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
1450 }
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
1451
24674
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1452 static GtkIMHtmlProtocol *
25013
956b2f650d31 Detect duplication registrations by substring.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25011
diff changeset
1453 imhtml_find_protocol(const char *url, gboolean reverse)
24674
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1454 {
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1455 GtkIMHtmlClass *klass;
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1456 GList *iter;
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1457 GtkIMHtmlProtocol *proto = NULL;
25013
956b2f650d31 Detect duplication registrations by substring.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25011
diff changeset
1458 int length = reverse ? strlen(url) : -1;
24674
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1459
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1460 klass = g_type_class_ref(GTK_TYPE_IMHTML);
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1461 for (iter = klass->protocols; iter; iter = iter->next) {
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1462 proto = iter->data;
25013
956b2f650d31 Detect duplication registrations by substring.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25011
diff changeset
1463 if (g_ascii_strncasecmp(url, proto->name, reverse ? MIN(length, proto->length) : proto->length) == 0) {
24674
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1464 return proto;
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1465 }
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1466 }
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1467 return NULL;
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1468 }
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1469
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1470 static void
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1471 imhtml_url_clicked(GtkIMHtml *imhtml, const char *url)
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1472 {
25013
956b2f650d31 Detect duplication registrations by substring.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25011
diff changeset
1473 GtkIMHtmlProtocol *proto = imhtml_find_protocol(url, FALSE);
24698
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1474 GtkIMHtmlLink *link;
24674
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1475 if (!proto)
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1476 return;
24698
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1477 link = g_new0(GtkIMHtmlLink, 1);
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1478 link->imhtml = g_object_ref(imhtml);
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1479 link->url = g_strdup(url);
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1480 proto->activate(imhtml, link); /* XXX: Do something with the return value? */
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1481 gtk_imhtml_link_destroy(link);
24674
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1482 }
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1483
10814
7e17cb56b019 [gaim-migrate @ 12468]
Luke Schierer <lschiere@pidgin.im>
parents: 10799
diff changeset
1484 /* Boring GTK+ stuff */
8519
13be07662047 [gaim-migrate @ 9258]
Gary Kramlich <grim@pidgin.im>
parents: 8516
diff changeset
1485 static void gtk_imhtml_class_init (GtkIMHtmlClass *klass)
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
1486 {
9007
87c8402bc0e3 [gaim-migrate @ 9783]
Tim Ringenbach <marv@pidgin.im>
parents: 8962
diff changeset
1487 GtkWidgetClass *widget_class = (GtkWidgetClass *) klass;
10100
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1488 GtkBindingSet *binding_set;
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
1489 GObjectClass *gobject_class;
8519
13be07662047 [gaim-migrate @ 9258]
Gary Kramlich <grim@pidgin.im>
parents: 8516
diff changeset
1490 gobject_class = (GObjectClass*) klass;
26828
ca76e7ad0d4b Oops, I must have been tired. I only replaced the first occurrence of these
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26727
diff changeset
1491 parent_class = g_type_class_ref(GTK_TYPE_TEXT_VIEW);
4417
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1492 signals[URL_CLICKED] = g_signal_new("url_clicked",
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1493 G_TYPE_FROM_CLASS(gobject_class),
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1494 G_SIGNAL_RUN_FIRST,
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1495 G_STRUCT_OFFSET(GtkIMHtmlClass, url_clicked),
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1496 NULL,
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1497 0,
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1498 g_cclosure_marshal_VOID__POINTER,
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1499 G_TYPE_NONE, 1,
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1500 G_TYPE_POINTER);
8506
76ce3a78b130 [gaim-migrate @ 9242]
Gary Kramlich <grim@pidgin.im>
parents: 8505
diff changeset
1501 signals[BUTTONS_UPDATE] = g_signal_new("format_buttons_update",
8420
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
1502 G_TYPE_FROM_CLASS(gobject_class),
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
1503 G_SIGNAL_RUN_FIRST,
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
1504 G_STRUCT_OFFSET(GtkIMHtmlClass, buttons_update),
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
1505 NULL,
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
1506 0,
10076
1ccc0286a4ae [gaim-migrate @ 11057]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10062
diff changeset
1507 g_cclosure_marshal_VOID__INT,
8420
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
1508 G_TYPE_NONE, 1,
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
1509 G_TYPE_INT);
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
1510 signals[TOGGLE_FORMAT] = g_signal_new("format_function_toggle",
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
1511 G_TYPE_FROM_CLASS(gobject_class),
10100
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1512 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
8420
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
1513 G_STRUCT_OFFSET(GtkIMHtmlClass, toggle_format),
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
1514 NULL,
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
1515 0,
10076
1ccc0286a4ae [gaim-migrate @ 11057]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10062
diff changeset
1516 g_cclosure_marshal_VOID__INT,
1ccc0286a4ae [gaim-migrate @ 11057]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10062
diff changeset
1517 G_TYPE_NONE, 1,
8420
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
1518 G_TYPE_INT);
8427
b99f5085af0a [gaim-migrate @ 9157]
Sean Egan <seanegan@pidgin.im>
parents: 8420
diff changeset
1519 signals[CLEAR_FORMAT] = g_signal_new("format_function_clear",
b99f5085af0a [gaim-migrate @ 9157]
Sean Egan <seanegan@pidgin.im>
parents: 8420
diff changeset
1520 G_TYPE_FROM_CLASS(gobject_class),
11385
38ca1438e055 [gaim-migrate @ 13612]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 11315
diff changeset
1521 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
8427
b99f5085af0a [gaim-migrate @ 9157]
Sean Egan <seanegan@pidgin.im>
parents: 8420
diff changeset
1522 G_STRUCT_OFFSET(GtkIMHtmlClass, clear_format),
b99f5085af0a [gaim-migrate @ 9157]
Sean Egan <seanegan@pidgin.im>
parents: 8420
diff changeset
1523 NULL,
b99f5085af0a [gaim-migrate @ 9157]
Sean Egan <seanegan@pidgin.im>
parents: 8420
diff changeset
1524 0,
10100
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1525 g_cclosure_marshal_VOID__VOID,
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1526 G_TYPE_NONE, 0);
8506
76ce3a78b130 [gaim-migrate @ 9242]
Gary Kramlich <grim@pidgin.im>
parents: 8505
diff changeset
1527 signals[UPDATE_FORMAT] = g_signal_new("format_function_update",
10100
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1528 G_TYPE_FROM_CLASS(gobject_class),
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1529 G_SIGNAL_RUN_FIRST,
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1530 G_STRUCT_OFFSET(GtkIMHtmlClass, update_format),
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1531 NULL,
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1532 0,
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1533 g_cclosure_marshal_VOID__VOID,
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1534 G_TYPE_NONE, 0);
10108
0897c42d6cb9 [gaim-migrate @ 11141]
Sean Egan <seanegan@pidgin.im>
parents: 10100
diff changeset
1535 signals[MESSAGE_SEND] = g_signal_new("message_send",
0897c42d6cb9 [gaim-migrate @ 11141]
Sean Egan <seanegan@pidgin.im>
parents: 10100
diff changeset
1536 G_TYPE_FROM_CLASS(gobject_class),
0897c42d6cb9 [gaim-migrate @ 11141]
Sean Egan <seanegan@pidgin.im>
parents: 10100
diff changeset
1537 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
0897c42d6cb9 [gaim-migrate @ 11141]
Sean Egan <seanegan@pidgin.im>
parents: 10100
diff changeset
1538 G_STRUCT_OFFSET(GtkIMHtmlClass, message_send),
0897c42d6cb9 [gaim-migrate @ 11141]
Sean Egan <seanegan@pidgin.im>
parents: 10100
diff changeset
1539 NULL,
0897c42d6cb9 [gaim-migrate @ 11141]
Sean Egan <seanegan@pidgin.im>
parents: 10100
diff changeset
1540 0, g_cclosure_marshal_VOID__VOID,
0897c42d6cb9 [gaim-migrate @ 11141]
Sean Egan <seanegan@pidgin.im>
parents: 10100
diff changeset
1541 G_TYPE_NONE, 0);
29909
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1542 signals[PASTE] = g_signal_new("paste",
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1543 G_TYPE_FROM_CLASS(gobject_class),
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1544 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1545 0,
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1546 NULL,
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1547 0, g_cclosure_marshal_VOID__STRING,
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1548 G_TYPE_NONE, 1, G_TYPE_STRING);
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1549 signals [UNDO] = g_signal_new ("undo",
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1550 G_TYPE_FROM_CLASS (klass),
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1551 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1552 G_STRUCT_OFFSET (GtkIMHtmlClass, undo),
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1553 NULL,
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1554 NULL,
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1555 gtksourceview_marshal_VOID__VOID,
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1556 G_TYPE_NONE,
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1557 0);
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1558 signals [REDO] = g_signal_new ("redo",
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1559 G_TYPE_FROM_CLASS (klass),
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1560 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1561 G_STRUCT_OFFSET (GtkIMHtmlClass, redo),
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1562 NULL,
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1563 NULL,
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1564 gtksourceview_marshal_VOID__VOID,
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1565 G_TYPE_NONE,
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1566 0);
17880
5e73968467e0 Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents: 17288
diff changeset
1567
5e73968467e0 Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents: 17288
diff changeset
1568
10100
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1569
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1570 klass->toggle_format = imhtml_toggle_format;
10108
0897c42d6cb9 [gaim-migrate @ 11141]
Sean Egan <seanegan@pidgin.im>
parents: 10100
diff changeset
1571 klass->message_send = imhtml_message_send;
12672
673e2a1d2954 [gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12635
diff changeset
1572 klass->clear_format = imhtml_clear_formatting;
24674
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1573 klass->url_clicked = imhtml_url_clicked;
17880
5e73968467e0 Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents: 17288
diff changeset
1574 klass->undo = gtk_imhtml_undo;
5e73968467e0 Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents: 17288
diff changeset
1575 klass->redo = gtk_imhtml_redo;
10184
543c9a84ce16 [gaim-migrate @ 11299]
Mark Doliner <markdoliner@pidgin.im>
parents: 10169
diff changeset
1576
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
1577 gobject_class->finalize = gtk_imhtml_finalize;
10184
543c9a84ce16 [gaim-migrate @ 11299]
Mark Doliner <markdoliner@pidgin.im>
parents: 10169
diff changeset
1578 widget_class->drag_motion = gtk_text_view_drag_motion;
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
1579 /* TODO: I _think_ this should be removed for GTK+ 3.0 */
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1580 /*widget_class->expose_event = gtk_imhtml_expose_event;*/
18968
2ddbe6473bc9 Cool! Override GtkTextView's size allocate function in GtkIMHtml to make sure that it stays scrolled to the bottom whenever it's resized. Fixes a major annoyance and possibly #938
Sean Egan <seanegan@pidgin.im>
parents: 18665
diff changeset
1581 parent_size_allocate = widget_class->size_allocate;
2ddbe6473bc9 Cool! Override GtkTextView's size allocate function in GtkIMHtml to make sure that it stays scrolled to the bottom whenever it's resized. Fixes a major annoyance and possibly #938
Sean Egan <seanegan@pidgin.im>
parents: 18665
diff changeset
1582 widget_class->size_allocate = gtk_imhtml_size_allocate;
23227
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
1583 parent_style_set = widget_class->style_set;
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
1584 widget_class->style_set = gtk_imhtml_style_set;
18968
2ddbe6473bc9 Cool! Override GtkTextView's size allocate function in GtkIMHtml to make sure that it stays scrolled to the bottom whenever it's resized. Fixes a major annoyance and possibly #938
Sean Egan <seanegan@pidgin.im>
parents: 18665
diff changeset
1585
9007
87c8402bc0e3 [gaim-migrate @ 9783]
Tim Ringenbach <marv@pidgin.im>
parents: 8962
diff changeset
1586 gtk_widget_class_install_style_property(widget_class, g_param_spec_boxed("hyperlink-color",
87c8402bc0e3 [gaim-migrate @ 9783]
Tim Ringenbach <marv@pidgin.im>
parents: 8962
diff changeset
1587 _("Hyperlink color"),
87c8402bc0e3 [gaim-migrate @ 9783]
Tim Ringenbach <marv@pidgin.im>
parents: 8962
diff changeset
1588 _("Color to draw hyperlinks."),
87c8402bc0e3 [gaim-migrate @ 9783]
Tim Ringenbach <marv@pidgin.im>
parents: 8962
diff changeset
1589 GDK_TYPE_COLOR, G_PARAM_READABLE));
24328
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
1590 gtk_widget_class_install_style_property(widget_class, g_param_spec_boxed("hyperlink-visited-color",
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
1591 _("Hyperlink visited color"),
27525
579b9d64b364 A semi-random collection of English spelling and grammatical changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 27359
diff changeset
1592 _("Color to draw hyperlink after it has been visited (or activated)."),
24328
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
1593 GDK_TYPE_COLOR, G_PARAM_READABLE));
10799
69ccc5c5518c [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
1594 gtk_widget_class_install_style_property(widget_class, g_param_spec_boxed("hyperlink-prelight-color",
69ccc5c5518c [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
1595 _("Hyperlink prelight color"),
69ccc5c5518c [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
1596 _("Color to draw hyperlinks when mouse is over them."),
69ccc5c5518c [gaim-migrate @ 12442]
Tim Ringenbach <marv@pidgin.im>
parents: 10798
diff changeset
1597 GDK_TYPE_COLOR, G_PARAM_READABLE));
21955
4014918b95fc Another patch from DHowett. This one adds conversation nick colors to gtkrc
Sean Egan <seanegan@pidgin.im>
parents: 21896
diff changeset
1598 gtk_widget_class_install_style_property(widget_class, g_param_spec_boxed("send-name-color",
4014918b95fc Another patch from DHowett. This one adds conversation nick colors to gtkrc
Sean Egan <seanegan@pidgin.im>
parents: 21896
diff changeset
1599 _("Sent Message Name Color"),
4014918b95fc Another patch from DHowett. This one adds conversation nick colors to gtkrc
Sean Egan <seanegan@pidgin.im>
parents: 21896
diff changeset
1600 _("Color to draw the name of a message you sent."),
4014918b95fc Another patch from DHowett. This one adds conversation nick colors to gtkrc
Sean Egan <seanegan@pidgin.im>
parents: 21896
diff changeset
1601 GDK_TYPE_COLOR, G_PARAM_READABLE));
4014918b95fc Another patch from DHowett. This one adds conversation nick colors to gtkrc
Sean Egan <seanegan@pidgin.im>
parents: 21896
diff changeset
1602 gtk_widget_class_install_style_property(widget_class, g_param_spec_boxed("receive-name-color",
4014918b95fc Another patch from DHowett. This one adds conversation nick colors to gtkrc
Sean Egan <seanegan@pidgin.im>
parents: 21896
diff changeset
1603 _("Received Message Name Color"),
4014918b95fc Another patch from DHowett. This one adds conversation nick colors to gtkrc
Sean Egan <seanegan@pidgin.im>
parents: 21896
diff changeset
1604 _("Color to draw the name of a message you received."),
4014918b95fc Another patch from DHowett. This one adds conversation nick colors to gtkrc
Sean Egan <seanegan@pidgin.im>
parents: 21896
diff changeset
1605 GDK_TYPE_COLOR, G_PARAM_READABLE));
4014918b95fc Another patch from DHowett. This one adds conversation nick colors to gtkrc
Sean Egan <seanegan@pidgin.im>
parents: 21896
diff changeset
1606 gtk_widget_class_install_style_property(widget_class, g_param_spec_boxed("highlight-name-color",
4014918b95fc Another patch from DHowett. This one adds conversation nick colors to gtkrc
Sean Egan <seanegan@pidgin.im>
parents: 21896
diff changeset
1607 _("\"Attention\" Name Color"),
4014918b95fc Another patch from DHowett. This one adds conversation nick colors to gtkrc
Sean Egan <seanegan@pidgin.im>
parents: 21896
diff changeset
1608 _("Color to draw the name of a message you received containing your name."),
4014918b95fc Another patch from DHowett. This one adds conversation nick colors to gtkrc
Sean Egan <seanegan@pidgin.im>
parents: 21896
diff changeset
1609 GDK_TYPE_COLOR, G_PARAM_READABLE));
4014918b95fc Another patch from DHowett. This one adds conversation nick colors to gtkrc
Sean Egan <seanegan@pidgin.im>
parents: 21896
diff changeset
1610 gtk_widget_class_install_style_property(widget_class, g_param_spec_boxed("action-name-color",
4014918b95fc Another patch from DHowett. This one adds conversation nick colors to gtkrc
Sean Egan <seanegan@pidgin.im>
parents: 21896
diff changeset
1611 _("Action Message Name Color"),
4014918b95fc Another patch from DHowett. This one adds conversation nick colors to gtkrc
Sean Egan <seanegan@pidgin.im>
parents: 21896
diff changeset
1612 _("Color to draw the name of an action message."),
4014918b95fc Another patch from DHowett. This one adds conversation nick colors to gtkrc
Sean Egan <seanegan@pidgin.im>
parents: 21896
diff changeset
1613 GDK_TYPE_COLOR, G_PARAM_READABLE));
23227
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
1614 gtk_widget_class_install_style_property(widget_class, g_param_spec_boxed("whisper-action-name-color",
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
1615 _("Action Message Name Color for Whispered Message"),
27525
579b9d64b364 A semi-random collection of English spelling and grammatical changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 27359
diff changeset
1616 _("Color to draw the name of a whispered action message."),
23227
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
1617 GDK_TYPE_COLOR, G_PARAM_READABLE));
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
1618 gtk_widget_class_install_style_property(widget_class, g_param_spec_boxed("whisper-name-color",
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
1619 _("Whisper Message Name Color"),
27525
579b9d64b364 A semi-random collection of English spelling and grammatical changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 27359
diff changeset
1620 _("Color to draw the name of a whispered message."),
23227
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
1621 GDK_TYPE_COLOR, G_PARAM_READABLE));
10100
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1622
22772
34ab3bb905cc Customize/disable the typing notification from gtkrc-2.0.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22703
diff changeset
1623 /* Customizable typing notification ... sort of. Example:
34ab3bb905cc Customize/disable the typing notification from gtkrc-2.0.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22703
diff changeset
1624 * GtkIMHtml::typing-notification-font = "monospace italic light 8.0"
34ab3bb905cc Customize/disable the typing notification from gtkrc-2.0.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22703
diff changeset
1625 * GtkIMHtml::typing-notification-color = "#ff0000"
34ab3bb905cc Customize/disable the typing notification from gtkrc-2.0.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22703
diff changeset
1626 * GtkIMHtml::typing-notification-enable = 1
34ab3bb905cc Customize/disable the typing notification from gtkrc-2.0.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22703
diff changeset
1627 */
34ab3bb905cc Customize/disable the typing notification from gtkrc-2.0.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22703
diff changeset
1628 gtk_widget_class_install_style_property(widget_class, g_param_spec_boxed("typing-notification-color",
34ab3bb905cc Customize/disable the typing notification from gtkrc-2.0.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22703
diff changeset
1629 _("Typing notification color"),
27525
579b9d64b364 A semi-random collection of English spelling and grammatical changes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 27359
diff changeset
1630 _("The color to use for the typing notification"),
22772
34ab3bb905cc Customize/disable the typing notification from gtkrc-2.0.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22703
diff changeset
1631 GDK_TYPE_COLOR, G_PARAM_READABLE));
34ab3bb905cc Customize/disable the typing notification from gtkrc-2.0.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22703
diff changeset
1632 gtk_widget_class_install_style_property(widget_class, g_param_spec_string("typing-notification-font",
34ab3bb905cc Customize/disable the typing notification from gtkrc-2.0.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22703
diff changeset
1633 _("Typing notification font"),
34ab3bb905cc Customize/disable the typing notification from gtkrc-2.0.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22703
diff changeset
1634 _("The font to use for the typing notification"),
34ab3bb905cc Customize/disable the typing notification from gtkrc-2.0.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22703
diff changeset
1635 "light 8.0", G_PARAM_READABLE));
34ab3bb905cc Customize/disable the typing notification from gtkrc-2.0.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22703
diff changeset
1636 gtk_widget_class_install_style_property(widget_class, g_param_spec_boolean("typing-notification-enable",
34ab3bb905cc Customize/disable the typing notification from gtkrc-2.0.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22703
diff changeset
1637 _("Enable typing notification"),
34ab3bb905cc Customize/disable the typing notification from gtkrc-2.0.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22703
diff changeset
1638 _("Enable typing notification"),
34ab3bb905cc Customize/disable the typing notification from gtkrc-2.0.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22703
diff changeset
1639 TRUE, G_PARAM_READABLE));
34ab3bb905cc Customize/disable the typing notification from gtkrc-2.0.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22703
diff changeset
1640
10100
4bbba369808a [gaim-migrate @ 11123]
Sean Egan <seanegan@pidgin.im>
parents: 10076
diff changeset
1641 binding_set = gtk_binding_set_by_class (parent_class);
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1642 gtk_binding_entry_add_signal (binding_set, GDK_KEY_b, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_BOLD);
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1643 gtk_binding_entry_add_signal (binding_set, GDK_KEY_i, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_ITALIC);
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1644 gtk_binding_entry_add_signal (binding_set, GDK_KEY_u, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_UNDERLINE);
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1645 gtk_binding_entry_add_signal (binding_set, GDK_KEY_plus, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_GROW);
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1646 gtk_binding_entry_add_signal (binding_set, GDK_KEY_equal, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_GROW);
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1647 gtk_binding_entry_add_signal (binding_set, GDK_KEY_minus, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_SHRINK);
10108
0897c42d6cb9 [gaim-migrate @ 11141]
Sean Egan <seanegan@pidgin.im>
parents: 10100
diff changeset
1648 binding_set = gtk_binding_set_by_class(klass);
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1649 gtk_binding_entry_add_signal (binding_set, GDK_KEY_r, GDK_CONTROL_MASK, "format_function_clear", 0);
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1650 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0, "message_send", 0);
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1651 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0, "message_send", 0);
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1652 gtk_binding_entry_add_signal (binding_set, GDK_KEY_z, GDK_CONTROL_MASK, "undo", 0);
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1653 gtk_binding_entry_add_signal (binding_set, GDK_KEY_z, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "redo", 0);
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1654 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F14, 0, "undo", 0);
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1655 gtk_binding_entry_add_signal(binding_set, GDK_KEY_v, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "paste", 1, G_TYPE_STRING, "text");
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
1656 }
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
1657
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
1658 static void gtk_imhtml_init (GtkIMHtml *imhtml)
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
1659 {
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
1660 imhtml->text_buffer = gtk_text_buffer_new(NULL);
17880
5e73968467e0 Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents: 17288
diff changeset
1661 imhtml->undo_manager = gtk_source_undo_manager_new(imhtml->text_buffer);
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
1662 gtk_text_view_set_buffer(GTK_TEXT_VIEW(imhtml), imhtml->text_buffer);
5105
3565a4c4de6a [gaim-migrate @ 5468]
David J. Brigada <brigada@prism.net>
parents: 5104
diff changeset
1663 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(imhtml), GTK_WRAP_WORD_CHAR);
22865
eeed3e121bed Move 2 of the 5 pixels' padding between paragraphs to above the line.
Will Thompson <resiak@pidgin.im>
parents: 22834
diff changeset
1664 gtk_text_view_set_pixels_above_lines(GTK_TEXT_VIEW(imhtml), 2);
eeed3e121bed Move 2 of the 5 pixels' padding between paragraphs to above the line.
Will Thompson <resiak@pidgin.im>
parents: 22834
diff changeset
1665 gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(imhtml), 3);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1666 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(imhtml), 2);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1667 gtk_text_view_set_right_margin(GTK_TEXT_VIEW(imhtml), 2);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1668 /*gtk_text_view_set_indent(GTK_TEXT_VIEW(imhtml), -15);*/
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
1669 /*gtk_text_view_set_justification(GTK_TEXT_VIEW(imhtml), GTK_JUSTIFY_FILL);*/
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1670
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
1671 /* These tags will be used often and can be reused--we create them on init and then apply them by name
8932
4b122cbfa7df [gaim-migrate @ 9702]
Tim Ringenbach <marv@pidgin.im>
parents: 8931
diff changeset
1672 * other tags (color, size, face, etc.) will have to be created and applied dynamically
9924
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
1673 * Note that even though we created SUB, SUP, and PRE tags here, we don't really
8932
4b122cbfa7df [gaim-migrate @ 9702]
Tim Ringenbach <marv@pidgin.im>
parents: 8931
diff changeset
1674 * apply them anywhere yet. */
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
1675 gtk_text_buffer_create_tag(imhtml->text_buffer, "BOLD", "weight", PANGO_WEIGHT_BOLD, NULL);
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
1676 gtk_text_buffer_create_tag(imhtml->text_buffer, "ITALICS", "style", PANGO_STYLE_ITALIC, NULL);
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
1677 gtk_text_buffer_create_tag(imhtml->text_buffer, "UNDERLINE", "underline", PANGO_UNDERLINE_SINGLE, NULL);
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
1678 gtk_text_buffer_create_tag(imhtml->text_buffer, "STRIKE", "strikethrough", TRUE, NULL);
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
1679 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUB", "rise", -5000, NULL);
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
1680 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUP", "rise", 5000, NULL);
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
1681 gtk_text_buffer_create_tag(imhtml->text_buffer, "PRE", "family", "Monospace", NULL);
7295
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
1682 gtk_text_buffer_create_tag(imhtml->text_buffer, "search", "background", "#22ff00", "weight", "bold", NULL);
23308
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
1683 gtk_text_buffer_create_tag(imhtml->text_buffer, "comment", "weight", PANGO_WEIGHT_NORMAL,
22486
e77232ab761f Disable invisible text things, if someone can conclusively prove this is
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 22276
diff changeset
1684 #if FALSE && GTK_CHECK_VERSION(2,10,10)
23308
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
1685 "invisible", FALSE,
22211
7f3cecdb079c disapproval of revision '2c96f5a301400781ce5fbf144ffdbae44f895281'
Sean Egan <seanegan@pidgin.im>
parents: 22210
diff changeset
1686 #endif
23308
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
1687 NULL);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1688
23227
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
1689 gtk_text_buffer_create_tag(imhtml->text_buffer, "send-name", "weight", PANGO_WEIGHT_BOLD, NULL);
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
1690 gtk_text_buffer_create_tag(imhtml->text_buffer, "receive-name", "weight", PANGO_WEIGHT_BOLD, NULL);
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
1691 gtk_text_buffer_create_tag(imhtml->text_buffer, "highlight-name", "weight", PANGO_WEIGHT_BOLD, NULL);
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
1692 gtk_text_buffer_create_tag(imhtml->text_buffer, "action-name", "weight", PANGO_WEIGHT_BOLD, NULL);
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
1693 gtk_text_buffer_create_tag(imhtml->text_buffer, "whisper-action-name", "weight", PANGO_WEIGHT_BOLD, NULL);
f2d8240d3487 Use text-tags to set the weight/color of the nick in conversations. This
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22970
diff changeset
1694 gtk_text_buffer_create_tag(imhtml->text_buffer, "whisper-name", "weight", PANGO_WEIGHT_BOLD, NULL);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1695
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
1696 /* When hovering over a link, we show the hand cursor--elsewhere we show the plain ol' pointer cursor */
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
1697 imhtml->hand_cursor = gdk_cursor_new (GDK_HAND2);
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
1698 imhtml->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1699 imhtml->text_cursor = gdk_cursor_new (GDK_XTERM);
2993
0340d0a8b810 [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
1700
6124
322206d79652 [gaim-migrate @ 6598]
Mark Doliner <markdoliner@pidgin.im>
parents: 6066
diff changeset
1701 imhtml->show_comments = TRUE;
4253
a1fa2170cb2d [gaim-migrate @ 4504]
Sean Egan <seanegan@pidgin.im>
parents: 4201
diff changeset
1702
4892
37b4a5ac5ebe [gaim-migrate @ 5222]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
1703 imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal,
4902
e7cb2fed937e [gaim-migrate @ 5236]
Nathan Walp <nwalp@pidgin.im>
parents: 4895
diff changeset
1704 g_free, (GDestroyNotify)gtk_smiley_tree_destroy);
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
1705 imhtml->default_smilies = gtk_smiley_tree_new();
4735
ac5f2489f6ee [gaim-migrate @ 5050]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4635
diff changeset
1706
ac5f2489f6ee [gaim-migrate @ 5050]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4635
diff changeset
1707 g_signal_connect(G_OBJECT(imhtml), "motion-notify-event", G_CALLBACK(gtk_motion_event_notify), NULL);
4944
032dac83798e [gaim-migrate @ 5278]
Robert McQueen <robot101@debian.org>
parents: 4926
diff changeset
1708 g_signal_connect(G_OBJECT(imhtml), "leave-notify-event", G_CALLBACK(gtk_leave_event_notify), NULL);
10946
63a41710fc94 [gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents: 10936
diff changeset
1709 g_signal_connect(G_OBJECT(imhtml), "enter-notify-event", G_CALLBACK(gtk_enter_event_notify), NULL);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1710 g_signal_connect(G_OBJECT(imhtml), "button_press_event", G_CALLBACK(gtk_imhtml_button_press_event), NULL);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1711 g_signal_connect(G_OBJECT(imhtml->text_buffer), "insert-text", G_CALLBACK(preinsert_cb), imhtml);
12673
4c8a20955e0b [gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12672
diff changeset
1712 g_signal_connect(G_OBJECT(imhtml->text_buffer), "delete_range", G_CALLBACK(delete_cb), imhtml);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1713 g_signal_connect_after(G_OBJECT(imhtml->text_buffer), "insert-text", G_CALLBACK(insert_cb), imhtml);
10169
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
1714 g_signal_connect_after(G_OBJECT(imhtml->text_buffer), "insert-child-anchor", G_CALLBACK(insert_ca_cb), imhtml);
8091
e2ffba819297 [gaim-migrate @ 8790]
Sean Egan <seanegan@pidgin.im>
parents: 8061
diff changeset
1715 gtk_drag_dest_set(GTK_WIDGET(imhtml), 0,
e2ffba819297 [gaim-migrate @ 8790]
Sean Egan <seanegan@pidgin.im>
parents: 8061
diff changeset
1716 link_drag_drop_targets, sizeof(link_drag_drop_targets) / sizeof(GtkTargetEntry),
e2ffba819297 [gaim-migrate @ 8790]
Sean Egan <seanegan@pidgin.im>
parents: 8061
diff changeset
1717 GDK_ACTION_COPY);
e2ffba819297 [gaim-migrate @ 8790]
Sean Egan <seanegan@pidgin.im>
parents: 8061
diff changeset
1718 g_signal_connect(G_OBJECT(imhtml), "drag_data_received", G_CALLBACK(gtk_imhtml_link_drag_rcv_cb), imhtml);
9300
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1719 g_signal_connect(G_OBJECT(imhtml), "drag_drop", G_CALLBACK(gtk_imhtml_link_drop_cb), imhtml);
8091
e2ffba819297 [gaim-migrate @ 8790]
Sean Egan <seanegan@pidgin.im>
parents: 8061
diff changeset
1720
7353
53cb39c73cf3 [gaim-migrate @ 7944]
Sean Egan <seanegan@pidgin.im>
parents: 7346
diff changeset
1721 g_signal_connect(G_OBJECT(imhtml), "copy-clipboard", G_CALLBACK(copy_clipboard_cb), NULL);
8698
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
1722 g_signal_connect(G_OBJECT(imhtml), "cut-clipboard", G_CALLBACK(cut_clipboard_cb), NULL);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1723 g_signal_connect(G_OBJECT(imhtml), "paste-clipboard", G_CALLBACK(paste_clipboard_cb), NULL);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1724 g_signal_connect_after(G_OBJECT(imhtml), "realize", G_CALLBACK(imhtml_realized_remove_primary), NULL);
8740
098a43943bba [gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents: 8735
diff changeset
1725 g_signal_connect(G_OBJECT(imhtml), "unrealize", G_CALLBACK(imhtml_destroy_add_primary), NULL);
29909
3b74346e22d5 Allow binding 'Paste as Plain Text'.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29855
diff changeset
1726 g_signal_connect(G_OBJECT(imhtml), "paste", G_CALLBACK(imhtml_paste_cb), NULL);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1727
29855
234f74a60570 I think this works around the problem with the Win32 Clipboard and GTK+ 2.16.
Daniel Atallah <datallah@pidgin.im>
parents: 29724
diff changeset
1728 #ifndef _WIN32
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1729 g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set",
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1730 G_CALLBACK(mark_set_so_update_selection_cb), imhtml);
29855
234f74a60570 I think this works around the problem with the Win32 Clipboard and GTK+ 2.16.
Daniel Atallah <datallah@pidgin.im>
parents: 29724
diff changeset
1731 #endif
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1732
10946
63a41710fc94 [gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents: 10936
diff changeset
1733 gtk_widget_add_events(GTK_WIDGET(imhtml),
63a41710fc94 [gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents: 10936
diff changeset
1734 GDK_LEAVE_NOTIFY_MASK | GDK_ENTER_NOTIFY_MASK);
4735
ac5f2489f6ee [gaim-migrate @ 5050]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4635
diff changeset
1735
ac5f2489f6ee [gaim-migrate @ 5050]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4635
diff changeset
1736 imhtml->tip = NULL;
ac5f2489f6ee [gaim-migrate @ 5050]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4635
diff changeset
1737 imhtml->tip_timer = 0;
ac5f2489f6ee [gaim-migrate @ 5050]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4635
diff changeset
1738 imhtml->tip_window = NULL;
4895
51794f61995e [gaim-migrate @ 5227]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4892
diff changeset
1739
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1740 imhtml->edit.bold = FALSE;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1741 imhtml->edit.italic = FALSE;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1742 imhtml->edit.underline = FALSE;
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1743 imhtml->edit.forecolor = NULL;
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1744 imhtml->edit.backcolor = NULL;
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1745 imhtml->edit.fontface = NULL;
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1746 imhtml->edit.fontsize = 0;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1747 imhtml->edit.link = NULL;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1748
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1749
4895
51794f61995e [gaim-migrate @ 5227]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4892
diff changeset
1750 imhtml->scalables = NULL;
16385
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
1751 imhtml->animations = g_queue_new();
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1752 gtk_imhtml_set_editable(imhtml, FALSE);
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1753 g_signal_connect(G_OBJECT(imhtml), "populate-popup",
8931
30432ceb156f [gaim-migrate @ 9701]
Tim Ringenbach <marv@pidgin.im>
parents: 8909
diff changeset
1754 G_CALLBACK(hijack_menu_cb), NULL);
2993
0340d0a8b810 [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
1755 }
0340d0a8b810 [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
1756
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
1757 GtkWidget *gtk_imhtml_new(void *a, void *b)
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
1758 {
4635
475ccd9dc3ac [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1759 return GTK_WIDGET(g_object_new(gtk_imhtml_get_type(), NULL));
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
1760 }
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
1761
9037
6ba358dfe075 [gaim-migrate @ 9813]
Kevin Stange <kstange@pidgin.im>
parents: 9034
diff changeset
1762 GType gtk_imhtml_get_type()
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
1763 {
9037
6ba358dfe075 [gaim-migrate @ 9813]
Kevin Stange <kstange@pidgin.im>
parents: 9034
diff changeset
1764 static GType imhtml_type = 0;
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
1765
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
1766 if (!imhtml_type) {
9037
6ba358dfe075 [gaim-migrate @ 9813]
Kevin Stange <kstange@pidgin.im>
parents: 9034
diff changeset
1767 static const GTypeInfo imhtml_info = {
4635
475ccd9dc3ac [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1768 sizeof(GtkIMHtmlClass),
475ccd9dc3ac [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1769 NULL,
475ccd9dc3ac [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1770 NULL,
475ccd9dc3ac [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1771 (GClassInitFunc) gtk_imhtml_class_init,
475ccd9dc3ac [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1772 NULL,
475ccd9dc3ac [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1773 NULL,
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
1774 sizeof (GtkIMHtml),
4635
475ccd9dc3ac [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1775 0,
12600
7ecd4441fdc7 [gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents: 12553
diff changeset
1776 (GInstanceInitFunc) gtk_imhtml_init,
7ecd4441fdc7 [gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents: 12553
diff changeset
1777 NULL
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
1778 };
4635
475ccd9dc3ac [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1779
475ccd9dc3ac [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1780 imhtml_type = g_type_register_static(gtk_text_view_get_type(),
475ccd9dc3ac [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
1781 "GtkIMHtml", &imhtml_info, 0);
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
1782 }
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
1783
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
1784 return imhtml_type;
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
1785 }
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
1786
24698
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1787 static void gtk_imhtml_link_destroy(GtkIMHtmlLink *link)
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1788 {
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1789 if (link->imhtml)
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1790 g_object_unref(link->imhtml);
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1791 if (link->tag)
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1792 g_object_unref(link->tag);
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1793 g_free(link->url);
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1794 g_free(link);
4417
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1795 }
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1796
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1797 /* The callback for an event on a link tag. */
24328
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
1798 static gboolean tag_event(GtkTextTag *tag, GObject *imhtml, GdkEvent *event, GtkTextIter *arg2, gpointer unused)
7be2af5c9129 Show visited links in a different color. This also plugs a memory leak
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23548
diff changeset
1799 {
4417
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1800 GdkEventButton *event_button = (GdkEventButton *) event;
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1801 if (GTK_IMHTML(imhtml)->editable)
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1802 return FALSE;
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
1803 if (event->type == GDK_BUTTON_RELEASE) {
8957
b65a01270451 [gaim-migrate @ 9731]
Tim Ringenbach <marv@pidgin.im>
parents: 8932
diff changeset
1804 if ((event_button->button == 1) || (event_button->button == 2)) {
4417
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1805 GtkTextIter start, end;
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1806 /* we shouldn't open a URL if the user has selected something: */
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1807 if (gtk_text_buffer_get_selection_bounds(
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
1808 gtk_text_iter_get_buffer(arg2), &start, &end))
4417
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1809 return FALSE;
24698
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1810 gtk_imhtml_activate_tag(GTK_IMHTML(imhtml), tag);
4417
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1811 return FALSE;
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1812 } else if(event_button->button == 3) {
24698
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1813 GList *children;
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1814 GtkWidget *menu;
24674
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1815 GtkIMHtmlProtocol *proto;
24698
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1816 GtkIMHtmlLink *link = g_new(GtkIMHtmlLink, 1);
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1817 link->imhtml = g_object_ref(imhtml);
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1818 link->url = g_strdup(g_object_get_data(G_OBJECT(tag), "link_url"));
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1819 link->tag = g_object_ref(tag);
4745
24867c379d37 [gaim-migrate @ 5060]
Nathan Walp <nwalp@pidgin.im>
parents: 4740
diff changeset
1820
5091
aee60723c147 [gaim-migrate @ 5453]
Ari Pollak <ari@debian.org>
parents: 5046
diff changeset
1821 /* Don't want the tooltip around if user right-clicked on link */
aee60723c147 [gaim-migrate @ 5453]
Ari Pollak <ari@debian.org>
parents: 5046
diff changeset
1822 if (GTK_IMHTML(imhtml)->tip_window) {
aee60723c147 [gaim-migrate @ 5453]
Ari Pollak <ari@debian.org>
parents: 5046
diff changeset
1823 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window);
aee60723c147 [gaim-migrate @ 5453]
Ari Pollak <ari@debian.org>
parents: 5046
diff changeset
1824 GTK_IMHTML(imhtml)->tip_window = NULL;
aee60723c147 [gaim-migrate @ 5453]
Ari Pollak <ari@debian.org>
parents: 5046
diff changeset
1825 }
aee60723c147 [gaim-migrate @ 5453]
Ari Pollak <ari@debian.org>
parents: 5046
diff changeset
1826 if (GTK_IMHTML(imhtml)->tip_timer) {
aee60723c147 [gaim-migrate @ 5453]
Ari Pollak <ari@debian.org>
parents: 5046
diff changeset
1827 g_source_remove(GTK_IMHTML(imhtml)->tip_timer);
aee60723c147 [gaim-migrate @ 5453]
Ari Pollak <ari@debian.org>
parents: 5046
diff changeset
1828 GTK_IMHTML(imhtml)->tip_timer = 0;
aee60723c147 [gaim-migrate @ 5453]
Ari Pollak <ari@debian.org>
parents: 5046
diff changeset
1829 }
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1830 if (GTK_IMHTML(imhtml)->editable)
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1831 gdk_window_set_cursor(event_button->window, GTK_IMHTML(imhtml)->text_cursor);
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1832 else
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
1833 gdk_window_set_cursor(event_button->window, GTK_IMHTML(imhtml)->arrow_cursor);
4417
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1834 menu = gtk_menu_new();
24698
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1835 g_object_set_data_full(G_OBJECT(menu), "x-imhtml-url-data", link,
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1836 (GDestroyNotify)gtk_imhtml_link_destroy);
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1837
25013
956b2f650d31 Detect duplication registrations by substring.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25011
diff changeset
1838 proto = imhtml_find_protocol(link->url, FALSE);
24698
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1839
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1840 if (proto && proto->context_menu) {
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1841 proto->context_menu(GTK_IMHTML(link->imhtml), link, menu);
7140
2670fa7da352 [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1842 }
24698
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1843
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1844 children = gtk_container_get_children(GTK_CONTAINER(menu));
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1845 if (!children) {
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1846 GtkWidget *item = gtk_menu_item_new_with_label(_("No actions available"));
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1847 gtk_widget_show(item);
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1848 gtk_widget_set_sensitive(item, FALSE);
10936
d42af9473789 [gaim-migrate @ 12720]
Alex Duggan
parents: 10901
diff changeset
1849 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
24698
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1850 } else {
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
1851 g_list_free(children);
7140
2670fa7da352 [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1852 }
2670fa7da352 [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
1853
4756
ee19a87a495f [gaim-migrate @ 5073]
Mark Doliner <markdoliner@pidgin.im>
parents: 4745
diff changeset
1854
4417
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1855 gtk_widget_show_all(menu);
4756
ee19a87a495f [gaim-migrate @ 5073]
Mark Doliner <markdoliner@pidgin.im>
parents: 4745
diff changeset
1856 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
ee19a87a495f [gaim-migrate @ 5073]
Mark Doliner <markdoliner@pidgin.im>
parents: 4745
diff changeset
1857 event_button->button, event_button->time);
4745
24867c379d37 [gaim-migrate @ 5060]
Nathan Walp <nwalp@pidgin.im>
parents: 4740
diff changeset
1858
4417
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1859 return TRUE;
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1860 }
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
1861 }
4417
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1862 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3)
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1863 return TRUE; /* Clicking the right mouse button on a link shouldn't
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1864 be caught by the regular GtkTextView menu */
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1865 else
43ddfb896fb5 [gaim-migrate @ 4690]
Ari Pollak <ari@debian.org>
parents: 4371
diff changeset
1866 return FALSE; /* Let clicks go through if we didn't catch anything */
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
1867 }
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
1868
9300
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1869 static gboolean
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1870 gtk_text_view_drag_motion (GtkWidget *widget,
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1871 GdkDragContext *context,
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1872 gint x,
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1873 gint y,
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1874 guint time)
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1875 {
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1876 GdkDragAction suggested_action = 0;
9300
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1877
10145
f1405f65ff41 [gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10110
diff changeset
1878 if (gtk_drag_dest_find_target (widget, context, NULL) == GDK_NONE) {
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1879 /* can't accept any of the offered targets */
9300
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1880 } else {
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1881 GtkWidget *source_widget;
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1882 suggested_action = gdk_drag_context_get_suggested_action(context);
9300
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1883 source_widget = gtk_drag_get_source_widget (context);
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1884 if (source_widget == widget) {
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1885 /* Default to MOVE, unless the user has
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1886 * pressed ctrl or alt to affect available actions
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1887 */
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1888 if ((gdk_drag_context_get_actions(context) & GDK_ACTION_MOVE) != 0)
9300
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1889 suggested_action = GDK_ACTION_MOVE;
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1890 }
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1891 }
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1892
10145
f1405f65ff41 [gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10110
diff changeset
1893 gdk_drag_status (context, suggested_action, time);
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1894
9300
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1895 /* TRUE return means don't propagate the drag motion to parent
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1896 * widgets that may also be drop sites.
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1897 */
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1898 return TRUE;
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1899 }
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1900
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1901 static void
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1902 gtk_imhtml_link_drop_cb(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer user_data)
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1903 {
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1904 GdkAtom target = gtk_drag_dest_find_target (widget, context, NULL);
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
1905
9300
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1906 if (target != GDK_NONE)
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1907 gtk_drag_get_data (widget, context, target, time);
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1908 else
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1909 gtk_drag_finish (context, FALSE, FALSE, time);
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1910
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1911 return;
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1912 }
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1913
8091
e2ffba819297 [gaim-migrate @ 8790]
Sean Egan <seanegan@pidgin.im>
parents: 8061
diff changeset
1914 static void
e2ffba819297 [gaim-migrate @ 8790]
Sean Egan <seanegan@pidgin.im>
parents: 8061
diff changeset
1915 gtk_imhtml_link_drag_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y,
11143
f606fb334190 [gaim-migrate @ 13207]
Mark Doliner <markdoliner@pidgin.im>
parents: 11069
diff changeset
1916 GtkSelectionData *sd, guint info, guint t, GtkIMHtml *imhtml)
8091
e2ffba819297 [gaim-migrate @ 8790]
Sean Egan <seanegan@pidgin.im>
parents: 8061
diff changeset
1917 {
9300
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1918 gchar **links;
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1919 gchar *link;
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1920 char *text = (char *) gtk_selection_data_get_data(sd);
9300
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1921 GtkTextMark *mark = gtk_text_buffer_get_insert(imhtml->text_buffer);
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1922 GtkTextIter iter;
10782
18cc41076f4e [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1923 gint i = 0;
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
1924 gint length = gtk_selection_data_get_length(sd);
9300
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1925
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1926 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark);
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1927
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
1928 if (gtk_imhtml_get_editable(imhtml) && text) {
9300
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1929 switch (info) {
10145
f1405f65ff41 [gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10110
diff changeset
1930 case GTK_IMHTML_DRAG_URL:
11143
f606fb334190 [gaim-migrate @ 13207]
Mark Doliner <markdoliner@pidgin.im>
parents: 11069
diff changeset
1931 /* TODO: Is it really ok to change sd->data...? */
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1932 purple_str_strip_char(text, '\r');
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1933
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1934 links = g_strsplit(text, "\n", 0);
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
1935 while ((link = links[i]) != NULL) {
24674
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1936 if (gtk_imhtml_is_protocol(link)) {
10782
18cc41076f4e [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1937 gchar *label;
18cc41076f4e [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1938
18cc41076f4e [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1939 if(links[i + 1])
18cc41076f4e [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1940 i++;
18cc41076f4e [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1941
18cc41076f4e [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1942 label = links[i];
18cc41076f4e [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1943
18cc41076f4e [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1944 gtk_imhtml_insert_link(imhtml, mark, link, label);
24674
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
1945 } else if (*link == '\0') {
9300
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1946 /* Ignore blank lines */
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1947 } else {
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1948 /* Special reasons, aka images being put in via other tag, etc. */
10345
7d7f8cfa2b4f [gaim-migrate @ 11556]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 10297
diff changeset
1949 /* ... don't pretend we handled it if we didn't */
7d7f8cfa2b4f [gaim-migrate @ 11556]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 10297
diff changeset
1950 gtk_drag_finish(dc, FALSE, FALSE, t);
10782
18cc41076f4e [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1951 g_strfreev(links);
10345
7d7f8cfa2b4f [gaim-migrate @ 11556]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 10297
diff changeset
1952 return;
9300
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1953 }
10782
18cc41076f4e [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1954
18cc41076f4e [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1955 i++;
8091
e2ffba819297 [gaim-migrate @ 8790]
Sean Egan <seanegan@pidgin.im>
parents: 8061
diff changeset
1956 }
10782
18cc41076f4e [gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents: 10777
diff changeset
1957 g_strfreev(links);
9300
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1958 break;
10145
f1405f65ff41 [gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10110
diff changeset
1959 case GTK_IMHTML_DRAG_HTML:
10243
6d75b29afc71 [gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10217
diff changeset
1960 {
6d75b29afc71 [gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10217
diff changeset
1961 char *utf8 = NULL;
6d75b29afc71 [gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10217
diff changeset
1962 /* Ewww. This is all because mozilla thinks that text/html is 'for internal use only.'
6d75b29afc71 [gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10217
diff changeset
1963 * as explained by this comment in gtkhtml:
6d75b29afc71 [gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10217
diff changeset
1964 *
6d75b29afc71 [gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10217
diff changeset
1965 * FIXME This hack decides the charset of the selection. It seems that
6d75b29afc71 [gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10217
diff changeset
1966 * mozilla/netscape alway use ucs2 for text/html
6d75b29afc71 [gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10217
diff changeset
1967 * and openoffice.org seems to always use utf8 so we try to validate
6d75b29afc71 [gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10217
diff changeset
1968 * the string as utf8 and if that fails we assume it is ucs2
6d75b29afc71 [gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10217
diff changeset
1969 *
6d75b29afc71 [gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10217
diff changeset
1970 * See also the comment on text/html here:
6d75b29afc71 [gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10217
diff changeset
1971 * http://mail.gnome.org/archives/gtk-devel-list/2001-September/msg00114.html
6d75b29afc71 [gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10217
diff changeset
1972 */
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1973 if (length >= 2 && !g_utf8_validate(text, length - 1, NULL)) {
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
1974 utf8 = utf16_to_utf8_with_bom_check(text, length);
10243
6d75b29afc71 [gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10217
diff changeset
1975
6d75b29afc71 [gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10217
diff changeset
1976 if (!utf8) {
22596
0854ae660ef4 Further changes to use UTF-16 instead of UCS-2. Also, fix #5167 by making sure that the encoding conversion worked before using the result.
Daniel Atallah <datallah@pidgin.im>
parents: 22595
diff changeset
1977 purple_debug_warning("gtkimhtml", "g_convert from UTF-16 failed in drag_rcv_cb\n");
9300
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1978 return;
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1979 }
10243
6d75b29afc71 [gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10217
diff changeset
1980 } else if (!(*text) || !g_utf8_validate(text, -1, NULL)) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15865
diff changeset
1981 purple_debug_warning("gtkimhtml", "empty string or invalid UTF-8 in drag_rcv_cb\n");
9300
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1982 return;
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1983 }
10243
6d75b29afc71 [gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10217
diff changeset
1984
6d75b29afc71 [gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10217
diff changeset
1985 gtk_imhtml_insert_html_at_iter(imhtml, utf8 ? utf8 : text, 0, &iter);
6d75b29afc71 [gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10217
diff changeset
1986 g_free(utf8);
9300
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1987 break;
10243
6d75b29afc71 [gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10217
diff changeset
1988 }
10145
f1405f65ff41 [gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10110
diff changeset
1989 case GTK_IMHTML_DRAG_TEXT:
f1405f65ff41 [gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10110
diff changeset
1990 if (!(*text) || !g_utf8_validate(text, -1, NULL)) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15865
diff changeset
1991 purple_debug_warning("gtkimhtml", "empty string or invalid UTF-8 in drag_rcv_cb\n");
10145
f1405f65ff41 [gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10110
diff changeset
1992 return;
f1405f65ff41 [gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10110
diff changeset
1993 } else {
10732
5e314ab498bf [gaim-migrate @ 12334]
Richard Laager <rlaager@pidgin.im>
parents: 10699
diff changeset
1994 char *tmp = g_markup_escape_text(text, -1);
10145
f1405f65ff41 [gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10110
diff changeset
1995 gtk_imhtml_insert_html_at_iter(imhtml, tmp, 0, &iter);
f1405f65ff41 [gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10110
diff changeset
1996 g_free(tmp);
f1405f65ff41 [gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10110
diff changeset
1997 }
f1405f65ff41 [gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10110
diff changeset
1998 break;
9300
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
1999 default:
10145
f1405f65ff41 [gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10110
diff changeset
2000 gtk_drag_finish(dc, FALSE, FALSE, t);
f1405f65ff41 [gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10110
diff changeset
2001 return;
8091
e2ffba819297 [gaim-migrate @ 8790]
Sean Egan <seanegan@pidgin.im>
parents: 8061
diff changeset
2002 }
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
2003 gtk_drag_finish(dc, TRUE,
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
2004 gdk_drag_context_get_actions(dc) == GDK_ACTION_MOVE, t);
8091
e2ffba819297 [gaim-migrate @ 8790]
Sean Egan <seanegan@pidgin.im>
parents: 8061
diff changeset
2005 } else {
e2ffba819297 [gaim-migrate @ 8790]
Sean Egan <seanegan@pidgin.im>
parents: 8061
diff changeset
2006 gtk_drag_finish(dc, FALSE, FALSE, t);
e2ffba819297 [gaim-migrate @ 8790]
Sean Egan <seanegan@pidgin.im>
parents: 8061
diff changeset
2007 }
e2ffba819297 [gaim-migrate @ 8790]
Sean Egan <seanegan@pidgin.im>
parents: 8061
diff changeset
2008 }
e2ffba819297 [gaim-migrate @ 8790]
Sean Egan <seanegan@pidgin.im>
parents: 8061
diff changeset
2009
9300
eefa5cc2f465 [gaim-migrate @ 10104]
Sean Egan <seanegan@pidgin.im>
parents: 9287
diff changeset
2010 static void gtk_smiley_tree_remove (GtkSmileyTree *tree,
4263
054b3ea4e7c5 [gaim-migrate @ 4514]
Sean Egan <seanegan@pidgin.im>
parents: 4253
diff changeset
2011 GtkIMHtmlSmiley *smiley)
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2012 {
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2013 GtkSmileyTree *t = tree;
4263
054b3ea4e7c5 [gaim-migrate @ 4514]
Sean Egan <seanegan@pidgin.im>
parents: 4253
diff changeset
2014 const gchar *x = smiley->smile;
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2015 gint len = 0;
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2016
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2017 while (*x) {
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2018 gchar *pos;
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2019
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2020 if (!t->values)
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2021 return;
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2022
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2023 pos = strchr (t->values->str, *x);
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2024 if (pos)
24544
75266af2c12b Fixed a compiler warning (and remove an unnessesary cast)
Marcus Lundblad <malu@pidgin.im>
parents: 24511
diff changeset
2025 t = t->children [pos - t->values->str];
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2026 else
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2027 return;
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2028
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2029 x++; len++;
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2030 }
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2031
4141
03df791352aa [gaim-migrate @ 4359]
Ari Pollak <ari@debian.org>
parents: 4140
diff changeset
2032 if (t->image) {
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2033 t->image = NULL;
4141
03df791352aa [gaim-migrate @ 4359]
Ari Pollak <ari@debian.org>
parents: 4140
diff changeset
2034 }
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2035 }
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2036
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2037 static gint
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2038 gtk_smiley_tree_lookup (GtkSmileyTree *tree,
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2039 const gchar *text)
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2040 {
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2041 GtkSmileyTree *t = tree;
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2042 const gchar *x = text;
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2043 gint len = 0;
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
2044 const gchar *amp;
8505
780845b42f5c [gaim-migrate @ 9241]
Kevin Stange <kstange@pidgin.im>
parents: 8498
diff changeset
2045 gint alen;
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2046
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2047 while (*x) {
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2048 gchar *pos;
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2049
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2050 if (!t->values)
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2051 break;
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2052
16144
4e022531d1c9 Patch cleanups:
Richard Laager <rlaager@pidgin.im>
parents: 16143
diff changeset
2053 if(*x == '&' && (amp = purple_markup_unescape_entity(x, &alen))) {
10865
f5bb66be81a0 [gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents: 10858
diff changeset
2054 gboolean matched = TRUE;
f5bb66be81a0 [gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents: 10858
diff changeset
2055 /* Make sure all chars of the unescaped value match */
f5bb66be81a0 [gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents: 10858
diff changeset
2056 while (*(amp + 1)) {
f5bb66be81a0 [gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents: 10858
diff changeset
2057 pos = strchr (t->values->str, *amp);
f5bb66be81a0 [gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents: 10858
diff changeset
2058 if (pos)
f5bb66be81a0 [gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents: 10858
diff changeset
2059 t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)];
f5bb66be81a0 [gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents: 10858
diff changeset
2060 else {
f5bb66be81a0 [gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents: 10858
diff changeset
2061 matched = FALSE;
f5bb66be81a0 [gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents: 10858
diff changeset
2062 break;
f5bb66be81a0 [gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents: 10858
diff changeset
2063 }
f5bb66be81a0 [gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents: 10858
diff changeset
2064 amp++;
f5bb66be81a0 [gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents: 10858
diff changeset
2065 }
f5bb66be81a0 [gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents: 10858
diff changeset
2066 if (!matched)
f5bb66be81a0 [gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents: 10858
diff changeset
2067 break;
f5bb66be81a0 [gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents: 10858
diff changeset
2068
f5bb66be81a0 [gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents: 10858
diff changeset
2069 pos = strchr (t->values->str, *amp);
8505
780845b42f5c [gaim-migrate @ 9241]
Kevin Stange <kstange@pidgin.im>
parents: 8498
diff changeset
2070 }
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
2071 else if (*x == '<') /* Because we're all WYSIWYG now, a '<'
9636
1648147987cd [gaim-migrate @ 10480]
Sean Egan <seanegan@pidgin.im>
parents: 9621
diff changeset
2072 * char should only appear as the start of a tag. Perhaps a safer (but costlier)
1648147987cd [gaim-migrate @ 10480]
Sean Egan <seanegan@pidgin.im>
parents: 9621
diff changeset
2073 * check would be to call gtk_imhtml_is_tag on it */
10600
0c0053f3316c [gaim-migrate @ 12022]
Tim Ringenbach <marv@pidgin.im>
parents: 10589
diff changeset
2074 break;
10865
f5bb66be81a0 [gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents: 10858
diff changeset
2075 else {
f5bb66be81a0 [gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents: 10858
diff changeset
2076 alen = 1;
f5bb66be81a0 [gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents: 10858
diff changeset
2077 pos = strchr (t->values->str, *x);
f5bb66be81a0 [gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents: 10858
diff changeset
2078 }
8505
780845b42f5c [gaim-migrate @ 9241]
Kevin Stange <kstange@pidgin.im>
parents: 8498
diff changeset
2079
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2080 if (pos)
7371
24aea59c277c [gaim-migrate @ 7966]
Nathan Walp <nwalp@pidgin.im>
parents: 7358
diff changeset
2081 t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)];
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2082 else
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2083 break;
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2084
10865
f5bb66be81a0 [gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents: 10858
diff changeset
2085 x += alen;
f5bb66be81a0 [gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents: 10858
diff changeset
2086 len += alen;
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2087 }
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2088
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2089 if (t->image)
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2090 return len;
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2091
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2092 return 0;
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2093 }
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2094
24392
51b7f65a712d Clean up the GtkSmileyTrees on active GtkIMHtml instances when a custom smiley
Marcus Lundblad <malu@pidgin.im>
parents: 24328
diff changeset
2095 static void
51b7f65a712d Clean up the GtkSmileyTrees on active GtkIMHtml instances when a custom smiley
Marcus Lundblad <malu@pidgin.im>
parents: 24328
diff changeset
2096 gtk_imhtml_disassociate_smiley_foreach(gpointer key, gpointer value,
51b7f65a712d Clean up the GtkSmileyTrees on active GtkIMHtml instances when a custom smiley
Marcus Lundblad <malu@pidgin.im>
parents: 24328
diff changeset
2097 gpointer user_data)
51b7f65a712d Clean up the GtkSmileyTrees on active GtkIMHtml instances when a custom smiley
Marcus Lundblad <malu@pidgin.im>
parents: 24328
diff changeset
2098 {
51b7f65a712d Clean up the GtkSmileyTrees on active GtkIMHtml instances when a custom smiley
Marcus Lundblad <malu@pidgin.im>
parents: 24328
diff changeset
2099 GtkSmileyTree *tree = (GtkSmileyTree *) value;
51b7f65a712d Clean up the GtkSmileyTrees on active GtkIMHtml instances when a custom smiley
Marcus Lundblad <malu@pidgin.im>
parents: 24328
diff changeset
2100 GtkIMHtmlSmiley *smiley = (GtkIMHtmlSmiley *) user_data;
51b7f65a712d Clean up the GtkSmileyTrees on active GtkIMHtml instances when a custom smiley
Marcus Lundblad <malu@pidgin.im>
parents: 24328
diff changeset
2101 gtk_smiley_tree_remove(tree, smiley);
51b7f65a712d Clean up the GtkSmileyTrees on active GtkIMHtml instances when a custom smiley
Marcus Lundblad <malu@pidgin.im>
parents: 24328
diff changeset
2102 }
51b7f65a712d Clean up the GtkSmileyTrees on active GtkIMHtml instances when a custom smiley
Marcus Lundblad <malu@pidgin.im>
parents: 24328
diff changeset
2103
51b7f65a712d Clean up the GtkSmileyTrees on active GtkIMHtml instances when a custom smiley
Marcus Lundblad <malu@pidgin.im>
parents: 24328
diff changeset
2104 static void
24588
b2c89babe134 Remove that hack involving GtkIMHtmlSmileys
Marcus Lundblad <malu@pidgin.im>
parents: 24587
diff changeset
2105 gtk_imhtml_disconnect_smiley(GtkIMHtml *imhtml, GtkIMHtmlSmiley *smiley)
b2c89babe134 Remove that hack involving GtkIMHtmlSmileys
Marcus Lundblad <malu@pidgin.im>
parents: 24587
diff changeset
2106 {
b2c89babe134 Remove that hack involving GtkIMHtmlSmileys
Marcus Lundblad <malu@pidgin.im>
parents: 24587
diff changeset
2107 smiley->imhtml = NULL;
b2c89babe134 Remove that hack involving GtkIMHtmlSmileys
Marcus Lundblad <malu@pidgin.im>
parents: 24587
diff changeset
2108 g_signal_handlers_disconnect_matched(imhtml, G_SIGNAL_MATCH_DATA, 0, 0,
b2c89babe134 Remove that hack involving GtkIMHtmlSmileys
Marcus Lundblad <malu@pidgin.im>
parents: 24587
diff changeset
2109 NULL, NULL, smiley);
b2c89babe134 Remove that hack involving GtkIMHtmlSmileys
Marcus Lundblad <malu@pidgin.im>
parents: 24587
diff changeset
2110 }
b2c89babe134 Remove that hack involving GtkIMHtmlSmileys
Marcus Lundblad <malu@pidgin.im>
parents: 24587
diff changeset
2111
b2c89babe134 Remove that hack involving GtkIMHtmlSmileys
Marcus Lundblad <malu@pidgin.im>
parents: 24587
diff changeset
2112 static void
24392
51b7f65a712d Clean up the GtkSmileyTrees on active GtkIMHtml instances when a custom smiley
Marcus Lundblad <malu@pidgin.im>
parents: 24328
diff changeset
2113 gtk_imhtml_disassociate_smiley(GtkIMHtmlSmiley *smiley)
51b7f65a712d Clean up the GtkSmileyTrees on active GtkIMHtml instances when a custom smiley
Marcus Lundblad <malu@pidgin.im>
parents: 24328
diff changeset
2114 {
24588
b2c89babe134 Remove that hack involving GtkIMHtmlSmileys
Marcus Lundblad <malu@pidgin.im>
parents: 24587
diff changeset
2115 if (smiley->imhtml) {
24392
51b7f65a712d Clean up the GtkSmileyTrees on active GtkIMHtml instances when a custom smiley
Marcus Lundblad <malu@pidgin.im>
parents: 24328
diff changeset
2116 gtk_smiley_tree_remove(smiley->imhtml->default_smilies, smiley);
25888
d0fdd378a635 Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents: 25854
diff changeset
2117 g_hash_table_foreach(smiley->imhtml->smiley_data,
24392
51b7f65a712d Clean up the GtkSmileyTrees on active GtkIMHtml instances when a custom smiley
Marcus Lundblad <malu@pidgin.im>
parents: 24328
diff changeset
2118 gtk_imhtml_disassociate_smiley_foreach, smiley);
24588
b2c89babe134 Remove that hack involving GtkIMHtmlSmileys
Marcus Lundblad <malu@pidgin.im>
parents: 24587
diff changeset
2119 g_signal_handlers_disconnect_matched(smiley->imhtml, G_SIGNAL_MATCH_DATA,
b2c89babe134 Remove that hack involving GtkIMHtmlSmileys
Marcus Lundblad <malu@pidgin.im>
parents: 24587
diff changeset
2120 0, 0, NULL, NULL, smiley);
24587
16c4d6e6e192 Don't try to remove GtkIMHtmlSmileys from smiley trees if the GtkIMHtml
Marcus Lundblad <malu@pidgin.im>
parents: 24569
diff changeset
2121 smiley->imhtml = NULL;
24392
51b7f65a712d Clean up the GtkSmileyTrees on active GtkIMHtml instances when a custom smiley
Marcus Lundblad <malu@pidgin.im>
parents: 24328
diff changeset
2122 }
51b7f65a712d Clean up the GtkSmileyTrees on active GtkIMHtml instances when a custom smiley
Marcus Lundblad <malu@pidgin.im>
parents: 24328
diff changeset
2123 }
51b7f65a712d Clean up the GtkSmileyTrees on active GtkIMHtml instances when a custom smiley
Marcus Lundblad <malu@pidgin.im>
parents: 24328
diff changeset
2124
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2125 void
4263
054b3ea4e7c5 [gaim-migrate @ 4514]
Sean Egan <seanegan@pidgin.im>
parents: 4253
diff changeset
2126 gtk_imhtml_associate_smiley (GtkIMHtml *imhtml,
10537
9ece7671fa62 [gaim-migrate @ 11890]
Mark Doliner <markdoliner@pidgin.im>
parents: 10526
diff changeset
2127 const gchar *sml,
4263
054b3ea4e7c5 [gaim-migrate @ 4514]
Sean Egan <seanegan@pidgin.im>
parents: 4253
diff changeset
2128 GtkIMHtmlSmiley *smiley)
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2129 {
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2130 GtkSmileyTree *tree;
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2131 g_return_if_fail (imhtml != NULL);
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2132 g_return_if_fail (GTK_IS_IMHTML (imhtml));
7371
24aea59c277c [gaim-migrate @ 7966]
Nathan Walp <nwalp@pidgin.im>
parents: 7358
diff changeset
2133
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2134 if (sml == NULL)
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2135 tree = imhtml->default_smilies;
12833
1f461f275b90 [gaim-migrate @ 15181]
Richard Laager <rlaager@pidgin.im>
parents: 12796
diff changeset
2136 else if (!(tree = g_hash_table_lookup(imhtml->smiley_data, sml))) {
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2137 tree = gtk_smiley_tree_new();
4892
37b4a5ac5ebe [gaim-migrate @ 5222]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
2138 g_hash_table_insert(imhtml->smiley_data, g_strdup(sml), tree);
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2139 }
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2140
24588
b2c89babe134 Remove that hack involving GtkIMHtmlSmileys
Marcus Lundblad <malu@pidgin.im>
parents: 24587
diff changeset
2141 /* need to disconnect old imhtml, if there is one */
b2c89babe134 Remove that hack involving GtkIMHtmlSmileys
Marcus Lundblad <malu@pidgin.im>
parents: 24587
diff changeset
2142 if (smiley->imhtml) {
b2c89babe134 Remove that hack involving GtkIMHtmlSmileys
Marcus Lundblad <malu@pidgin.im>
parents: 24587
diff changeset
2143 g_signal_handlers_disconnect_matched(smiley->imhtml, G_SIGNAL_MATCH_DATA,
b2c89babe134 Remove that hack involving GtkIMHtmlSmileys
Marcus Lundblad <malu@pidgin.im>
parents: 24587
diff changeset
2144 0, 0, NULL, NULL, smiley);
b2c89babe134 Remove that hack involving GtkIMHtmlSmileys
Marcus Lundblad <malu@pidgin.im>
parents: 24587
diff changeset
2145 }
25888
d0fdd378a635 Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents: 25854
diff changeset
2146
12335
d0a2da9e75c0 [gaim-migrate @ 14639]
Tim Ringenbach <marv@pidgin.im>
parents: 12253
diff changeset
2147 smiley->imhtml = imhtml;
d0a2da9e75c0 [gaim-migrate @ 14639]
Tim Ringenbach <marv@pidgin.im>
parents: 12253
diff changeset
2148
4263
054b3ea4e7c5 [gaim-migrate @ 4514]
Sean Egan <seanegan@pidgin.im>
parents: 4253
diff changeset
2149 gtk_smiley_tree_insert (tree, smiley);
25888
d0fdd378a635 Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents: 25854
diff changeset
2150
24588
b2c89babe134 Remove that hack involving GtkIMHtmlSmileys
Marcus Lundblad <malu@pidgin.im>
parents: 24587
diff changeset
2151 /* connect destroy signal for the imhtml */
25888
d0fdd378a635 Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents: 25854
diff changeset
2152 g_signal_connect(imhtml, "destroy", G_CALLBACK(gtk_imhtml_disconnect_smiley),
24588
b2c89babe134 Remove that hack involving GtkIMHtmlSmileys
Marcus Lundblad <malu@pidgin.im>
parents: 24587
diff changeset
2153 smiley);
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2154 }
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2155
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2156 static gboolean
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2157 gtk_imhtml_is_smiley (GtkIMHtml *imhtml,
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2158 GSList *fonts,
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2159 const gchar *text,
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2160 gint *len)
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2161 {
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2162 GtkSmileyTree *tree;
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
2163 GtkIMHtmlFontDetail *font;
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2164 char *sml = NULL;
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2165
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2166 if (fonts) {
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2167 font = fonts->data;
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2168 sml = font->sml;
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2169 }
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2170
9029
4670ebf1c180 [gaim-migrate @ 9805]
Tim Ringenbach <marv@pidgin.im>
parents: 9028
diff changeset
2171 if (!sml)
4670ebf1c180 [gaim-migrate @ 9805]
Tim Ringenbach <marv@pidgin.im>
parents: 9028
diff changeset
2172 sml = imhtml->protocol_name;
4670ebf1c180 [gaim-migrate @ 9805]
Tim Ringenbach <marv@pidgin.im>
parents: 9028
diff changeset
2173
4670ebf1c180 [gaim-migrate @ 9805]
Tim Ringenbach <marv@pidgin.im>
parents: 9028
diff changeset
2174 if (!sml || !(tree = g_hash_table_lookup(imhtml->smiley_data, sml)))
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2175 tree = imhtml->default_smilies;
9029
4670ebf1c180 [gaim-migrate @ 9805]
Tim Ringenbach <marv@pidgin.im>
parents: 9028
diff changeset
2176
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2177 if (tree == NULL)
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2178 return FALSE;
7371
24aea59c277c [gaim-migrate @ 7966]
Nathan Walp <nwalp@pidgin.im>
parents: 7358
diff changeset
2179
8505
780845b42f5c [gaim-migrate @ 9241]
Kevin Stange <kstange@pidgin.im>
parents: 8498
diff changeset
2180 *len = gtk_smiley_tree_lookup (tree, text);
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2181 return (*len > 0);
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2182 }
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2183
29724
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2184 static GtkIMHtmlSmiley *gtk_imhtml_smiley_get_from_tree(GtkSmileyTree *t, const gchar *text)
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2185 {
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2186 const gchar *x = text;
29724
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2187 gchar *pos;
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2188
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2189 if (t == NULL)
29724
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2190 return NULL;
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2191
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2192 while (*x) {
29724
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2193 if (!t->values)
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2194 return NULL;
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2195
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2196 pos = strchr(t->values->str, *x);
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2197 if (!pos)
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2198 return NULL;
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2199
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2200 t = t->children[GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)];
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2201 x++;
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2202 }
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2203
10526
05b5c6d4090d [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
2204 return t->image;
05b5c6d4090d [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
2205 }
05b5c6d4090d [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
2206
29724
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2207 GtkIMHtmlSmiley *
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2208 gtk_imhtml_smiley_get(GtkIMHtml *imhtml, const gchar *sml, const gchar *text)
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2209 {
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2210 GtkIMHtmlSmiley *ret;
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2211
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2212 /* Look for custom smileys first */
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2213 if (sml != NULL) {
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2214 ret = gtk_imhtml_smiley_get_from_tree(g_hash_table_lookup(imhtml->smiley_data, sml), text);
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2215 if (ret != NULL)
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2216 return ret;
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2217 }
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2218
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2219 /* Fall back to check for default smileys */
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2220 return gtk_imhtml_smiley_get_from_tree(imhtml->default_smilies, text);
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2221 }
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2222
11677
89c2ab8d2ebf [gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents: 11586
diff changeset
2223 static GdkPixbufAnimation *
17009
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
2224 gtk_smiley_get_image(GtkIMHtmlSmiley *smiley)
10526
05b5c6d4090d [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
2225 {
29724
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2226 if (!smiley->icon) {
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2227 if (smiley->file) {
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2228 smiley->icon = gdk_pixbuf_animation_new_from_file(smiley->file, NULL);
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2229 } else if (smiley->loader) {
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2230 smiley->icon = gdk_pixbuf_loader_get_animation(smiley->loader);
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2231 if (smiley->icon)
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2232 g_object_ref(G_OBJECT(smiley->icon));
1a6689974d33 Minor cleanup. Hopefully this code has a little less duplication and
Mark Doliner <markdoliner@pidgin.im>
parents: 29721
diff changeset
2233 }
10526
05b5c6d4090d [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
2234 }
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
2235
10526
05b5c6d4090d [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
2236 return smiley->icon;
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2237 }
8890
0a37b4a8ff32 [gaim-migrate @ 9659]
Kevin Stange <kstange@pidgin.im>
parents: 8881
diff changeset
2238
25017
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
2239 #define VALID_TAG(x) do { \
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
2240 if (!g_ascii_strncasecmp (string, x ">", strlen (x ">"))) { \
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
2241 if (tag) *tag = g_strndup (string, strlen (x)); \
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
2242 if (len) *len = strlen (x) + 1; \
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2243 return TRUE; \
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2244 } \
25017
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
2245 if (type) (*type)++; \
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
2246 } while (0)
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
2247
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
2248 #define VALID_OPT_TAG(x) do { \
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
2249 if (!g_ascii_strncasecmp (string, x " ", strlen (x " "))) { \
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2250 const gchar *c = string + strlen (x " "); \
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2251 gchar e = '"'; \
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2252 gboolean quote = FALSE; \
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2253 while (*c) { \
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2254 if (*c == '"' || *c == '\'') { \
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2255 if (quote && (*c == e)) \
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2256 quote = !quote; \
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2257 else if (!quote) { \
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2258 quote = !quote; \
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2259 e = *c; \
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2260 } \
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2261 } else if (!quote && (*c == '>')) \
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2262 break; \
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2263 c++; \
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2264 } \
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2265 if (*c) { \
25017
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
2266 if (tag) *tag = g_strndup (string, c - string); \
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
2267 if (len) *len = c - string + 1; \
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2268 return TRUE; \
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2269 } \
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2270 } \
25017
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
2271 if (type) (*type)++; \
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
2272 } while (0)
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
2273
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
2274
1472
ce83d12b7df9 [gaim-migrate @ 1482]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 1463
diff changeset
2275 static gboolean
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2276 gtk_imhtml_is_tag (const gchar *string,
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2277 gchar **tag,
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2278 gint *len,
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2279 gint *type)
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2280 {
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2281 char *close;
25017
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
2282 if (type)
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
2283 *type = 1;
8118
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
2284
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2285 if (!(close = strchr (string, '>')))
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2286 return FALSE;
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2287
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2288 VALID_TAG ("B");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2289 VALID_TAG ("BOLD");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2290 VALID_TAG ("/B");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2291 VALID_TAG ("/BOLD");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2292 VALID_TAG ("I");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2293 VALID_TAG ("ITALIC");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2294 VALID_TAG ("/I");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2295 VALID_TAG ("/ITALIC");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2296 VALID_TAG ("U");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2297 VALID_TAG ("UNDERLINE");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2298 VALID_TAG ("/U");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2299 VALID_TAG ("/UNDERLINE");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2300 VALID_TAG ("S");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2301 VALID_TAG ("STRIKE");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2302 VALID_TAG ("/S");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2303 VALID_TAG ("/STRIKE");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2304 VALID_TAG ("SUB");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2305 VALID_TAG ("/SUB");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2306 VALID_TAG ("SUP");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2307 VALID_TAG ("/SUP");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2308 VALID_TAG ("PRE");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2309 VALID_TAG ("/PRE");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2310 VALID_TAG ("TITLE");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2311 VALID_TAG ("/TITLE");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2312 VALID_TAG ("BR");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2313 VALID_TAG ("HR");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2314 VALID_TAG ("/FONT");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2315 VALID_TAG ("/A");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2316 VALID_TAG ("P");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2317 VALID_TAG ("/P");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2318 VALID_TAG ("H3");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2319 VALID_TAG ("/H3");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2320 VALID_TAG ("HTML");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2321 VALID_TAG ("/HTML");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2322 VALID_TAG ("BODY");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2323 VALID_TAG ("/BODY");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2324 VALID_TAG ("FONT");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2325 VALID_TAG ("HEAD");
2993
0340d0a8b810 [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
2326 VALID_TAG ("/HEAD");
0340d0a8b810 [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
2327 VALID_TAG ("BINARY");
0340d0a8b810 [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
2328 VALID_TAG ("/BINARY");
5093
7761492245e6 [gaim-migrate @ 5455]
Nathan Walp <nwalp@pidgin.im>
parents: 5091
diff changeset
2329
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2330 VALID_OPT_TAG ("HR");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2331 VALID_OPT_TAG ("FONT");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2332 VALID_OPT_TAG ("BODY");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2333 VALID_OPT_TAG ("A");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2334 VALID_OPT_TAG ("IMG");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2335 VALID_OPT_TAG ("P");
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2336 VALID_OPT_TAG ("H3");
5093
7761492245e6 [gaim-migrate @ 5455]
Nathan Walp <nwalp@pidgin.im>
parents: 5091
diff changeset
2337 VALID_OPT_TAG ("HTML");
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2338
5101
b771f92a4f10 [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2339 VALID_TAG ("CITE");
b771f92a4f10 [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2340 VALID_TAG ("/CITE");
b771f92a4f10 [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2341 VALID_TAG ("EM");
b771f92a4f10 [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2342 VALID_TAG ("/EM");
b771f92a4f10 [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2343 VALID_TAG ("STRONG");
b771f92a4f10 [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2344 VALID_TAG ("/STRONG");
b771f92a4f10 [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2345
5104
2a09bf67e875 [gaim-migrate @ 5467]
Nathan Walp <nwalp@pidgin.im>
parents: 5101
diff changeset
2346 VALID_OPT_TAG ("SPAN");
2a09bf67e875 [gaim-migrate @ 5467]
Nathan Walp <nwalp@pidgin.im>
parents: 5101
diff changeset
2347 VALID_TAG ("/SPAN");
5174
7d34d000f3fa [gaim-migrate @ 5538]
Nathan Walp <nwalp@pidgin.im>
parents: 5118
diff changeset
2348 VALID_TAG ("BR/"); /* hack until gtkimhtml handles things better */
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents: 6882
diff changeset
2349 VALID_TAG ("IMG");
8026
91fe30ffb897 [gaim-migrate @ 8706]
Nathan Walp <nwalp@pidgin.im>
parents: 7991
diff changeset
2350 VALID_TAG("SPAN");
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2351 VALID_OPT_TAG("BR");
7988
fe4616ea76c3 [gaim-migrate @ 8665]
Nathan Walp <nwalp@pidgin.im>
parents: 7961
diff changeset
2352
4793
1da93f6c80f3 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
2353 if (!g_ascii_strncasecmp(string, "!--", strlen ("!--"))) {
2954
fc07d855731d [gaim-migrate @ 2967]
Christian Hammond <chipx86@chipx86.com>
parents: 2898
diff changeset
2354 gchar *e = strstr (string + strlen("!--"), "-->");
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2355 if (e) {
25017
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
2356 if (len)
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
2357 *len = e - string + strlen ("-->");
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
2358 if (tag)
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
2359 *tag = g_strndup (string + strlen ("!--"), *len - strlen ("!---->"));
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2360 return TRUE;
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2361 }
8118
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
2362 }
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
2363
25017
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
2364 if (type)
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
2365 *type = -1;
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
2366 if (len)
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
2367 *len = close - string + 1;
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
2368 if (tag)
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
2369 *tag = g_strndup(string, *len - 1);
19733
ec657d978c5a disapproval of revision 'f08436883bb16f29affdc63e9fd86ff278ed368f'
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19732
diff changeset
2370 return TRUE;
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2371 }
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2372
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2373 static gchar*
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2374 gtk_imhtml_get_html_opt (gchar *tag,
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2375 const gchar *opt)
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2376 {
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2377 gchar *t = tag;
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2378 gchar *e, *a;
5177
7f8a27af0846 [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2379 gchar *val;
7f8a27af0846 [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2380 gint len;
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
2381 const gchar *c;
5177
7f8a27af0846 [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2382 GString *ret;
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2383
4793
1da93f6c80f3 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
2384 while (g_ascii_strncasecmp (t, opt, strlen (opt))) {
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2385 gboolean quote = FALSE;
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2386 if (*t == '\0') break;
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2387 while (*t && !((*t == ' ') && !quote)) {
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2388 if (*t == '\"')
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2389 quote = ! quote;
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2390 t++;
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2391 }
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2392 while (*t && (*t == ' ')) t++;
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2393 }
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2394
4793
1da93f6c80f3 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
2395 if (!g_ascii_strncasecmp (t, opt, strlen (opt))) {
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2396 t += strlen (opt);
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2397 } else {
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2398 return NULL;
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2399 }
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2400
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2401 if ((*t == '\"') || (*t == '\'')) {
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2402 e = a = ++t;
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2403 while (*e && (*e != *(t - 1))) e++;
2993
0340d0a8b810 [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
2404 if (*e == '\0') {
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2405 return NULL;
5177
7f8a27af0846 [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2406 } else
7f8a27af0846 [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2407 val = g_strndup(a, e - a);
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2408 } else {
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2409 e = a = t;
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2410 while (*e && !isspace ((gint) *e)) e++;
5177
7f8a27af0846 [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2411 val = g_strndup(a, e - a);
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2412 }
5177
7f8a27af0846 [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2413
7f8a27af0846 [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2414 ret = g_string_new("");
7f8a27af0846 [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2415 e = val;
7f8a27af0846 [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2416 while(*e) {
16144
4e022531d1c9 Patch cleanups:
Richard Laager <rlaager@pidgin.im>
parents: 16143
diff changeset
2417 if((c = purple_markup_unescape_entity(e, &len))) {
7280
f00e23f50698 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
2418 ret = g_string_append(ret, c);
5177
7f8a27af0846 [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2419 e += len;
7f8a27af0846 [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2420 } else {
19325
4ae1add93886 Thanks sadrul. Fixes #2277
Sean Egan <seanegan@pidgin.im>
parents: 19103
diff changeset
2421 gunichar uni = g_utf8_get_char(e);
4ae1add93886 Thanks sadrul. Fixes #2277
Sean Egan <seanegan@pidgin.im>
parents: 19103
diff changeset
2422 ret = g_string_append_unichar(ret, uni);
4ae1add93886 Thanks sadrul. Fixes #2277
Sean Egan <seanegan@pidgin.im>
parents: 19103
diff changeset
2423 e = g_utf8_next_char(e);
5177
7f8a27af0846 [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2424 }
7f8a27af0846 [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2425 }
7f8a27af0846 [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2426
7f8a27af0846 [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
2427 g_free(val);
8568
66907b37ce85 [gaim-migrate @ 9316]
Mark Doliner <markdoliner@pidgin.im>
parents: 8566
diff changeset
2428
66907b37ce85 [gaim-migrate @ 9316]
Mark Doliner <markdoliner@pidgin.im>
parents: 8566
diff changeset
2429 return g_string_free(ret, FALSE);
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2430 }
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2431
8334
63e80b767766 [gaim-migrate @ 9058]
Nathan Owens
parents: 8317
diff changeset
2432 /* returns if the beginning of the text is a protocol. If it is the protocol, returns the length so
63e80b767766 [gaim-migrate @ 9058]
Nathan Owens
parents: 8317
diff changeset
2433 the caller knows how long the protocol string is. */
12412
8abe3226695e [gaim-migrate @ 14719]
Richard Laager <rlaager@pidgin.im>
parents: 12335
diff changeset
2434 static int gtk_imhtml_is_protocol(const char *text)
8334
63e80b767766 [gaim-migrate @ 9058]
Nathan Owens
parents: 8317
diff changeset
2435 {
25013
956b2f650d31 Detect duplication registrations by substring.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25011
diff changeset
2436 GtkIMHtmlProtocol *proto = imhtml_find_protocol(text, FALSE);
24674
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
2437 return proto ? proto->length : 0;
8334
63e80b767766 [gaim-migrate @ 9058]
Nathan Owens
parents: 8317
diff changeset
2438 }
63e80b767766 [gaim-migrate @ 9058]
Nathan Owens
parents: 8317
diff changeset
2439
28940
e0f3781f6397 Fix scrolling bug for very busy chat rooms.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28935
diff changeset
2440 static gboolean smooth_scroll_cb(gpointer data);
e0f3781f6397 Fix scrolling bug for very busy chat rooms.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28935
diff changeset
2441
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2442 /*
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15865
diff changeset
2443 <KingAnt> marv: The two IM image functions in oscar are purple_odc_send_im and purple_odc_incoming
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2444
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2445
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2446 [19:58] <Robot101> marv: images go into the imgstore, a refcounted... well.. hash. :)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2447 [19:59] <KingAnt> marv: I think the image tag used by the core is something like <img id="#"/>
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
2448 [19:59] Ro0tSiEgE robert42 RobFlynn Robot101 ross22 roz
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15865
diff changeset
2449 [20:00] <KingAnt> marv: Where the ID is the what is returned when you add the image to the imgstore using purple_imgstore_add
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2450 [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?
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2451 [20:00] <KingAnt> marv: Right
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2452 [20:00] <marv> alright
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2453
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2454 Here's my plan with IMImages. make gtk_imhtml_[append|insert]_text_with_images instead just
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2455 gtkimhtml_[append|insert]_text (hrm maybe it should be called html instead of text), add a
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15865
diff changeset
2456 function for purple to register for look up images, i.e. gtk_imhtml_set_get_img_fnc, so that
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2457 images can be looked up like that, instead of passing a GSList of them.
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2458 */
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2459
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2460 void gtk_imhtml_append_text_with_images (GtkIMHtml *imhtml,
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2461 const gchar *text,
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2462 GtkIMHtmlOptions options,
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2463 GSList *unused)
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
2464 {
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2465 GtkTextIter iter, ins, sel;
22803
e1f64090d32e Do not show tooltips for <HR> or <IMG>s in gtkimhtml. Fixes #5480.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22772
diff changeset
2466 int ins_offset = 0, sel_offset = 0;
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2467 gboolean fixins = FALSE, fixsel = FALSE;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2468
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2469 g_return_if_fail (imhtml != NULL);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2470 g_return_if_fail (GTK_IS_IMHTML (imhtml));
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2471 g_return_if_fail (text != NULL);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2472
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2473
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2474 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2475 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &ins, gtk_text_buffer_get_insert(imhtml->text_buffer));
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2476 if (gtk_text_iter_equal(&iter, &ins) && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2477 fixins = TRUE;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2478 ins_offset = gtk_text_iter_get_offset(&ins);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2479 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2480
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2481 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &sel, gtk_text_buffer_get_selection_bound(imhtml->text_buffer));
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2482 if (gtk_text_iter_equal(&iter, &sel) && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2483 fixsel = TRUE;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2484 sel_offset = gtk_text_iter_get_offset(&sel);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2485 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2486
22803
e1f64090d32e Do not show tooltips for <HR> or <IMG>s in gtkimhtml. Fixes #5480.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22772
diff changeset
2487 if (!(options & GTK_IMHTML_NO_SCROLL)) {
e1f64090d32e Do not show tooltips for <HR> or <IMG>s in gtkimhtml. Fixes #5480.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22772
diff changeset
2488 GdkRectangle rect;
e1f64090d32e Do not show tooltips for <HR> or <IMG>s in gtkimhtml. Fixes #5480.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22772
diff changeset
2489 int y, height;
e1f64090d32e Do not show tooltips for <HR> or <IMG>s in gtkimhtml. Fixes #5480.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22772
diff changeset
2490
e1f64090d32e Do not show tooltips for <HR> or <IMG>s in gtkimhtml. Fixes #5480.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22772
diff changeset
2491 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect);
e1f64090d32e Do not show tooltips for <HR> or <IMG>s in gtkimhtml. Fixes #5480.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22772
diff changeset
2492 gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(imhtml), &iter, &y, &height);
e1f64090d32e Do not show tooltips for <HR> or <IMG>s in gtkimhtml. Fixes #5480.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22772
diff changeset
2493
e1f64090d32e Do not show tooltips for <HR> or <IMG>s in gtkimhtml. Fixes #5480.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22772
diff changeset
2494 if (((y + height) - (rect.y + rect.height)) > height &&
e1f64090d32e Do not show tooltips for <HR> or <IMG>s in gtkimhtml. Fixes #5480.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22772
diff changeset
2495 gtk_text_buffer_get_char_count(imhtml->text_buffer)) {
28940
e0f3781f6397 Fix scrolling bug for very busy chat rooms.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28935
diff changeset
2496 /* If we are in the middle of smooth-scrolling, then take a scroll step.
e0f3781f6397 Fix scrolling bug for very busy chat rooms.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28935
diff changeset
2497 * If we are not in the middle of smooth-scrolling, that means we were
e0f3781f6397 Fix scrolling bug for very busy chat rooms.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28935
diff changeset
2498 * not looking at the end of the buffer before the new text was added,
e0f3781f6397 Fix scrolling bug for very busy chat rooms.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28935
diff changeset
2499 * so do not scroll. */
e0f3781f6397 Fix scrolling bug for very busy chat rooms.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28935
diff changeset
2500 if (imhtml->scroll_time)
e0f3781f6397 Fix scrolling bug for very busy chat rooms.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28935
diff changeset
2501 smooth_scroll_cb(imhtml);
e0f3781f6397 Fix scrolling bug for very busy chat rooms.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28935
diff changeset
2502 else
e0f3781f6397 Fix scrolling bug for very busy chat rooms.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28935
diff changeset
2503 options |= GTK_IMHTML_NO_SCROLL;
22803
e1f64090d32e Do not show tooltips for <HR> or <IMG>s in gtkimhtml. Fixes #5480.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22772
diff changeset
2504 }
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2505 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2506
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2507 gtk_imhtml_insert_html_at_iter(imhtml, text, options, &iter);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2508
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2509 if (fixins) {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2510 gtk_text_buffer_get_iter_at_offset(imhtml->text_buffer, &ins, ins_offset);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2511 gtk_text_buffer_move_mark(imhtml->text_buffer, gtk_text_buffer_get_insert(imhtml->text_buffer), &ins);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2512 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2513
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2514 if (fixsel) {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2515 gtk_text_buffer_get_iter_at_offset(imhtml->text_buffer, &sel, sel_offset);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2516 gtk_text_buffer_move_mark(imhtml->text_buffer, gtk_text_buffer_get_selection_bound(imhtml->text_buffer), &sel);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2517 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2518
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2519 if (!(options & GTK_IMHTML_NO_SCROLL)) {
12553
52b3403a1690 [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2520 gtk_imhtml_scroll_to_end(imhtml, (options & GTK_IMHTML_USE_SMOOTHSCROLLING));
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2521 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2522 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2523
11006
fe7360eddcb5 [gaim-migrate @ 12866]
Ted Percival
parents: 10946
diff changeset
2524 #define MAX_SCROLL_TIME 0.4 /* seconds */
fe7360eddcb5 [gaim-migrate @ 12866]
Ted Percival
parents: 10946
diff changeset
2525 #define SCROLL_DELAY 33 /* milliseconds */
fe7360eddcb5 [gaim-migrate @ 12866]
Ted Percival
parents: 10946
diff changeset
2526
fe7360eddcb5 [gaim-migrate @ 12866]
Ted Percival
parents: 10946
diff changeset
2527 /*
fe7360eddcb5 [gaim-migrate @ 12866]
Ted Percival
parents: 10946
diff changeset
2528 * Smoothly scroll a GtkIMHtml.
fe7360eddcb5 [gaim-migrate @ 12866]
Ted Percival
parents: 10946
diff changeset
2529 *
fe7360eddcb5 [gaim-migrate @ 12866]
Ted Percival
parents: 10946
diff changeset
2530 * @return TRUE if the window needs to be scrolled further, FALSE if we're at the bottom.
fe7360eddcb5 [gaim-migrate @ 12866]
Ted Percival
parents: 10946
diff changeset
2531 */
28940
e0f3781f6397 Fix scrolling bug for very busy chat rooms.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28935
diff changeset
2532 static gboolean smooth_scroll_cb(gpointer data)
10798
d1aae5d8adb2 [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
2533 {
d1aae5d8adb2 [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
2534 GtkIMHtml *imhtml = data;
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
2535 GtkAdjustment *adj = gtk_text_view_get_vadjustment(GTK_TEXT_VIEW(imhtml));
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
2536 gdouble max_val = gtk_adjustment_get_upper(adj) - gtk_adjustment_get_page_size(adj);
19055
43f5771c45f4 Eliminate some unnecessary scrolling activity.
Daniel Atallah <datallah@pidgin.im>
parents: 18985
diff changeset
2537 gdouble scroll_val = gtk_adjustment_get_value(adj) + ((max_val - gtk_adjustment_get_value(adj)) / 3);
11006
fe7360eddcb5 [gaim-migrate @ 12866]
Ted Percival
parents: 10946
diff changeset
2538
fe7360eddcb5 [gaim-migrate @ 12866]
Ted Percival
parents: 10946
diff changeset
2539 g_return_val_if_fail(imhtml->scroll_time != NULL, FALSE);
fe7360eddcb5 [gaim-migrate @ 12866]
Ted Percival
parents: 10946
diff changeset
2540
19055
43f5771c45f4 Eliminate some unnecessary scrolling activity.
Daniel Atallah <datallah@pidgin.im>
parents: 18985
diff changeset
2541 if (g_timer_elapsed(imhtml->scroll_time, NULL) > MAX_SCROLL_TIME || scroll_val >= max_val) {
11006
fe7360eddcb5 [gaim-migrate @ 12866]
Ted Percival
parents: 10946
diff changeset
2542 /* time's up. jump to the end and kill the timer */
fe7360eddcb5 [gaim-migrate @ 12866]
Ted Percival
parents: 10946
diff changeset
2543 gtk_adjustment_set_value(adj, max_val);
10798
d1aae5d8adb2 [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
2544 g_timer_destroy(imhtml->scroll_time);
d1aae5d8adb2 [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
2545 imhtml->scroll_time = NULL;
28940
e0f3781f6397 Fix scrolling bug for very busy chat rooms.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28935
diff changeset
2546 g_source_remove(imhtml->scroll_src);
e0f3781f6397 Fix scrolling bug for very busy chat rooms.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28935
diff changeset
2547 imhtml->scroll_src = 0;
10798
d1aae5d8adb2 [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
2548 return FALSE;
11006
fe7360eddcb5 [gaim-migrate @ 12866]
Ted Percival
parents: 10946
diff changeset
2549 }
fe7360eddcb5 [gaim-migrate @ 12866]
Ted Percival
parents: 10946
diff changeset
2550
fe7360eddcb5 [gaim-migrate @ 12866]
Ted Percival
parents: 10946
diff changeset
2551 /* scroll by 1/3rd the remaining distance */
19055
43f5771c45f4 Eliminate some unnecessary scrolling activity.
Daniel Atallah <datallah@pidgin.im>
parents: 18985
diff changeset
2552 gtk_adjustment_set_value(adj, scroll_val);
11006
fe7360eddcb5 [gaim-migrate @ 12866]
Ted Percival
parents: 10946
diff changeset
2553 return TRUE;
10798
d1aae5d8adb2 [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
2554 }
d1aae5d8adb2 [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
2555
12553
52b3403a1690 [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2556 static gboolean scroll_idle_cb(gpointer data)
52b3403a1690 [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2557 {
52b3403a1690 [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2558 GtkIMHtml *imhtml = data;
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
2559 GtkAdjustment *adj = gtk_text_view_get_vadjustment(GTK_TEXT_VIEW(imhtml));
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
2560 if (adj) {
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
2561 gtk_adjustment_set_value(adj, gtk_adjustment_get_upper(adj) -
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
2562 gtk_adjustment_get_page_size(adj));
12553
52b3403a1690 [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2563 }
52b3403a1690 [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2564 imhtml->scroll_src = 0;
52b3403a1690 [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2565 return FALSE;
52b3403a1690 [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2566 }
52b3403a1690 [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2567
52b3403a1690 [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2568 void gtk_imhtml_scroll_to_end(GtkIMHtml *imhtml, gboolean smooth)
8729
4a677fc61cd3 [gaim-migrate @ 9484]
Tim Ringenbach <marv@pidgin.im>
parents: 8726
diff changeset
2569 {
10798
d1aae5d8adb2 [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
2570 if (imhtml->scroll_time)
d1aae5d8adb2 [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
2571 g_timer_destroy(imhtml->scroll_time);
d1aae5d8adb2 [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
2572 if (imhtml->scroll_src)
d1aae5d8adb2 [gaim-migrate @ 12441]
Tim Ringenbach <marv@pidgin.im>
parents: 10797
diff changeset
2573 g_source_remove(imhtml->scroll_src);
12553
52b3403a1690 [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2574 if(smooth) {
52b3403a1690 [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2575 imhtml->scroll_time = g_timer_new();
28940
e0f3781f6397 Fix scrolling bug for very busy chat rooms.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28935
diff changeset
2576 imhtml->scroll_src = g_timeout_add_full(G_PRIORITY_LOW, SCROLL_DELAY, smooth_scroll_cb, imhtml, NULL);
12553
52b3403a1690 [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2577 } else {
52b3403a1690 [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2578 imhtml->scroll_time = NULL;
52b3403a1690 [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2579 imhtml->scroll_src = g_idle_add_full(G_PRIORITY_LOW, scroll_idle_cb, imhtml, NULL);
52b3403a1690 [gaim-migrate @ 14871]
Nathan Walp <nwalp@pidgin.im>
parents: 12412
diff changeset
2580 }
8729
4a677fc61cd3 [gaim-migrate @ 9484]
Tim Ringenbach <marv@pidgin.im>
parents: 8726
diff changeset
2581 }
4a677fc61cd3 [gaim-migrate @ 9484]
Tim Ringenbach <marv@pidgin.im>
parents: 8726
diff changeset
2582
24509
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2583 /* CSS colors are either rgb (x,y,z) or #hex
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2584 * we need to convert to hex if it is RGB */
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2585 static gchar*
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2586 parse_css_color(gchar *in_color)
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2587 {
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2588 char *tmp = in_color;
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2589
24510
925061f2b31e Make the CSS rgb() color parsing more robust. khc noted that it wouldn't work
Daniel Atallah <datallah@pidgin.im>
parents: 24509
diff changeset
2590 if (*tmp == 'r' && *(++tmp) == 'g' && *(++tmp) == 'b' && *(++tmp)) {
24509
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2591 int rgbval[] = {0, 0, 0};
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2592 int count = 0;
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2593 const char *v_start;
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2594
24510
925061f2b31e Make the CSS rgb() color parsing more robust. khc noted that it wouldn't work
Daniel Atallah <datallah@pidgin.im>
parents: 24509
diff changeset
2595 while (*tmp && g_ascii_isspace(*tmp))
925061f2b31e Make the CSS rgb() color parsing more robust. khc noted that it wouldn't work
Daniel Atallah <datallah@pidgin.im>
parents: 24509
diff changeset
2596 tmp++;
925061f2b31e Make the CSS rgb() color parsing more robust. khc noted that it wouldn't work
Daniel Atallah <datallah@pidgin.im>
parents: 24509
diff changeset
2597 if (*tmp != '(') {
925061f2b31e Make the CSS rgb() color parsing more robust. khc noted that it wouldn't work
Daniel Atallah <datallah@pidgin.im>
parents: 24509
diff changeset
2598 /* We don't support rgba() */
925061f2b31e Make the CSS rgb() color parsing more robust. khc noted that it wouldn't work
Daniel Atallah <datallah@pidgin.im>
parents: 24509
diff changeset
2599 purple_debug_warning("gtkimhtml", "Invalid rgb CSS color in '%s'!\n", in_color);
925061f2b31e Make the CSS rgb() color parsing more robust. khc noted that it wouldn't work
Daniel Atallah <datallah@pidgin.im>
parents: 24509
diff changeset
2600 return in_color;
925061f2b31e Make the CSS rgb() color parsing more robust. khc noted that it wouldn't work
Daniel Atallah <datallah@pidgin.im>
parents: 24509
diff changeset
2601 }
925061f2b31e Make the CSS rgb() color parsing more robust. khc noted that it wouldn't work
Daniel Atallah <datallah@pidgin.im>
parents: 24509
diff changeset
2602 tmp++;
925061f2b31e Make the CSS rgb() color parsing more robust. khc noted that it wouldn't work
Daniel Atallah <datallah@pidgin.im>
parents: 24509
diff changeset
2603
24509
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2604 while (count < 3) {
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2605 /* Skip any leading spaces */
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2606 while (*tmp && g_ascii_isspace(*tmp))
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2607 tmp++;
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2608
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2609 /* Find the subsequent contiguous digits */
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2610 v_start = tmp;
24510
925061f2b31e Make the CSS rgb() color parsing more robust. khc noted that it wouldn't work
Daniel Atallah <datallah@pidgin.im>
parents: 24509
diff changeset
2611 if (*v_start == '-')
925061f2b31e Make the CSS rgb() color parsing more robust. khc noted that it wouldn't work
Daniel Atallah <datallah@pidgin.im>
parents: 24509
diff changeset
2612 tmp++;
24509
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2613 while (*tmp && g_ascii_isdigit(*tmp))
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2614 tmp++;
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2615
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2616 if (tmp != v_start) {
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2617 char prev = *tmp;
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2618 *tmp = '\0';
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2619 rgbval[count] = atoi(v_start);
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2620 *tmp = prev;
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2621
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2622 /* deal with % */
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2623 while (*tmp && g_ascii_isspace(*tmp))
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2624 tmp++;
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2625 if (*tmp == '%') {
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2626 rgbval[count] = (rgbval[count] / 100.0) * 255;
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2627 tmp++;
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2628 }
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2629 } else {
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2630 purple_debug_warning("gtkimhtml", "Invalid rgb CSS color in '%s'!\n", in_color);
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2631 return in_color;
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2632 }
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2633
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2634 if (rgbval[count] > 255) {
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2635 rgbval[count] = 255;
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2636 } else if (rgbval[count] < 0) {
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2637 rgbval[count] = 0;
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2638 }
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2639
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2640 while (*tmp && g_ascii_isspace(*tmp))
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2641 tmp++;
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2642 if (*tmp == ',')
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2643 tmp++;
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2644
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2645 count++;
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2646 }
25888
d0fdd378a635 Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents: 25854
diff changeset
2647
24509
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2648 g_free(in_color);
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2649 return g_strdup_printf("#%02X%02X%02X", rgbval[0], rgbval[1], rgbval[2]);
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2650 }
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2651
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2652 return in_color;
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2653 }
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
2654
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2655 void gtk_imhtml_insert_html_at_iter(GtkIMHtml *imhtml,
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2656 const gchar *text,
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2657 GtkIMHtmlOptions options,
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2658 GtkTextIter *iter)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2659 {
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2660 GdkRectangle rect;
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2661 gint pos = 0;
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2662 gchar *ws;
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2663 gchar *tag;
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2664 gchar *bg = NULL;
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents: 6882
diff changeset
2665 gint len;
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2666 gint tlen, smilelen, wpos=0;
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2667 gint type;
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2668 const gchar *c;
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
2669 const gchar *amp;
8334
63e80b767766 [gaim-migrate @ 9058]
Nathan Owens
parents: 8317
diff changeset
2670 gint len_protocol;
15379
4be41dcd3794 [gaim-migrate @ 18108]
Sean Egan <seanegan@pidgin.im>
parents: 15331
diff changeset
2671
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
2672 guint bold = 0,
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
2673 italics = 0,
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
2674 underline = 0,
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
2675 strike = 0,
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
2676 sub = 0,
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
2677 sup = 0,
1691
c8bd41036372 [gaim-migrate @ 1701]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 1647
diff changeset
2678 title = 0,
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2679 pre = 0;
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
2680
10217
0ba0263c657f [gaim-migrate @ 11345]
Daniel Westermann-Clark
parents: 10184
diff changeset
2681 gboolean br = FALSE;
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
2682 gboolean align_right = FALSE;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
2683 gboolean rtl_direction = FALSE;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
2684 gint align_line = 0;
15420
2dfadb432902 [gaim-migrate @ 18151]
Sean Egan <seanegan@pidgin.im>
parents: 15411
diff changeset
2685
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2686 GSList *fonts = NULL;
8506
76ce3a78b130 [gaim-migrate @ 9242]
Gary Kramlich <grim@pidgin.im>
parents: 8505
diff changeset
2687 GObject *object;
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2688 GtkIMHtmlScalable *scalable = NULL;
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2689
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2690 g_return_if_fail (imhtml != NULL);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2691 g_return_if_fail (GTK_IS_IMHTML (imhtml));
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2692 g_return_if_fail (text != NULL);
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2693 c = text;
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents: 6882
diff changeset
2694 len = strlen(text);
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2695 ws = g_malloc(len + 1);
25007
ef8bc1f4a6ba Pass only the URL scheme to gtkimhtml and let it add the colon automatically.
Richard Laager <rlaager@pidgin.im>
parents: 24698
diff changeset
2696 ws[0] = '\0';
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
2697
29378
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
2698 g_object_set_data(G_OBJECT(imhtml), "gtkimhtml_numsmileys_thismsg", GINT_TO_POINTER(0));
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
2699
22834
1394e7efb818 Smiley insertions can be undone with this fix. References #5577. But redo
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22810
diff changeset
2700 gtk_text_buffer_begin_user_action(imhtml->text_buffer);
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2701 while (pos < len) {
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2702 if (*c == '<' && gtk_imhtml_is_tag (c + 1, &tag, &tlen, &type)) {
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2703 c++;
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2704 pos++;
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2705 ws[wpos] = '\0';
10217
0ba0263c657f [gaim-migrate @ 11345]
Daniel Westermann-Clark
parents: 10184
diff changeset
2706 br = FALSE;
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2707 switch (type)
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2708 {
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2709 case 1: /* B */
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2710 case 2: /* BOLD */
5101
b771f92a4f10 [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2711 case 54: /* STRONG */
11485
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2712 if (!(options & GTK_IMHTML_NO_FORMATTING)) {
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2713 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2714
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2715 if ((bold == 0) && (imhtml->format_functions & GTK_IMHTML_BOLD))
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2716 gtk_imhtml_toggle_bold(imhtml);
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2717 bold++;
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2718 ws[0] = '\0'; wpos = 0;
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2719 }
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2720 break;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2721 case 3: /* /B */
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2722 case 4: /* /BOLD */
5101
b771f92a4f10 [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2723 case 55: /* /STRONG */
11485
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2724 if (!(options & GTK_IMHTML_NO_FORMATTING)) {
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2725 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2726 ws[0] = '\0'; wpos = 0;
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2727
14010
a47143a57c82 [gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents: 13552
diff changeset
2728 if (bold) {
11485
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2729 bold--;
14010
a47143a57c82 [gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents: 13552
diff changeset
2730 if ((bold == 0) && (imhtml->format_functions & GTK_IMHTML_BOLD) && !imhtml->wbfo)
a47143a57c82 [gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents: 13552
diff changeset
2731 gtk_imhtml_toggle_bold(imhtml);
a47143a57c82 [gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents: 13552
diff changeset
2732 }
11485
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2733 }
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2734 break;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2735 case 5: /* I */
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2736 case 6: /* ITALIC */
5101
b771f92a4f10 [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2737 case 52: /* EM */
11485
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2738 if (!(options & GTK_IMHTML_NO_FORMATTING)) {
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2739 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2740 ws[0] = '\0'; wpos = 0;
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2741 if ((italics == 0) && (imhtml->format_functions & GTK_IMHTML_ITALIC))
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2742 gtk_imhtml_toggle_italic(imhtml);
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2743 italics++;
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2744 }
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2745 break;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2746 case 7: /* /I */
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2747 case 8: /* /ITALIC */
5101
b771f92a4f10 [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
2748 case 53: /* /EM */
11485
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2749 if (!(options & GTK_IMHTML_NO_FORMATTING)) {
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2750 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2751 ws[0] = '\0'; wpos = 0;
14010
a47143a57c82 [gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents: 13552
diff changeset
2752 if (italics) {
11485
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2753 italics--;
14010
a47143a57c82 [gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents: 13552
diff changeset
2754 if ((italics == 0) && (imhtml->format_functions & GTK_IMHTML_ITALIC) && !imhtml->wbfo)
a47143a57c82 [gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents: 13552
diff changeset
2755 gtk_imhtml_toggle_italic(imhtml);
a47143a57c82 [gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents: 13552
diff changeset
2756 }
11485
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2757 }
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2758 break;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2759 case 9: /* U */
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2760 case 10: /* UNDERLINE */
11485
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2761 if (!(options & GTK_IMHTML_NO_FORMATTING)) {
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2762 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2763 ws[0] = '\0'; wpos = 0;
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2764 if ((underline == 0) && (imhtml->format_functions & GTK_IMHTML_UNDERLINE))
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2765 gtk_imhtml_toggle_underline(imhtml);
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2766 underline++;
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2767 }
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2768 break;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2769 case 11: /* /U */
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2770 case 12: /* /UNDERLINE */
11485
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2771 if (!(options & GTK_IMHTML_NO_FORMATTING)) {
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2772 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2773 ws[0] = '\0'; wpos = 0;
14010
a47143a57c82 [gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents: 13552
diff changeset
2774 if (underline) {
11485
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2775 underline--;
14010
a47143a57c82 [gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents: 13552
diff changeset
2776 if ((underline == 0) && (imhtml->format_functions & GTK_IMHTML_UNDERLINE) && !imhtml->wbfo)
a47143a57c82 [gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents: 13552
diff changeset
2777 gtk_imhtml_toggle_underline(imhtml);
a47143a57c82 [gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents: 13552
diff changeset
2778 }
11485
fe334b13d1d0 [gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents: 11385
diff changeset
2779 }
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2780 break;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2781 case 13: /* S */
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2782 case 14: /* STRIKE */
9924
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
2783 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
2784 ws[0] = '\0'; wpos = 0;
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
2785 if ((strike == 0) && (imhtml->format_functions & GTK_IMHTML_STRIKE))
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
2786 gtk_imhtml_toggle_strike(imhtml);
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2787 strike++;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2788 break;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2789 case 15: /* /S */
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2790 case 16: /* /STRIKE */
9924
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
2791 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
2792 ws[0] = '\0'; wpos = 0;
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2793 if (strike)
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2794 strike--;
9924
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
2795 if ((strike == 0) && (imhtml->format_functions & GTK_IMHTML_STRIKE) && !imhtml->wbfo)
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
2796 gtk_imhtml_toggle_strike(imhtml);
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2797 break;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2798 case 17: /* SUB */
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2799 /* FIXME: reimpliment this */
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2800 sub++;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2801 break;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2802 case 18: /* /SUB */
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2803 /* FIXME: reimpliment this */
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2804 if (sub)
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2805 sub--;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2806 break;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2807 case 19: /* SUP */
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2808 /* FIXME: reimplement this */
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2809 sup++;
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2810 break;
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2811 case 20: /* /SUP */
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2812 /* FIXME: reimplement this */
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2813 if (sup)
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2814 sup--;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2815 break;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2816 case 21: /* PRE */
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2817 /* FIXME: reimplement this */
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2818 pre++;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2819 break;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2820 case 22: /* /PRE */
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2821 /* FIXME: reimplement this */
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2822 if (pre)
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2823 pre--;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2824 break;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2825 case 23: /* TITLE */
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2826 /* FIXME: what was this supposed to do anyway? */
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2827 title++;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2828 break;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2829 case 24: /* /TITLE */
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2830 /* FIXME: make this undo whatever 23 was supposed to do */
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2831 if (title) {
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2832 if (options & GTK_IMHTML_NO_TITLE) {
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2833 wpos = 0;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2834 ws [wpos] = '\0';
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2835 }
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2836 title--;
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2837 }
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2838 break;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2839 case 25: /* BR */
5174
7d34d000f3fa [gaim-migrate @ 5538]
Nathan Walp <nwalp@pidgin.im>
parents: 5118
diff changeset
2840 case 58: /* BR/ */
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2841 case 61: /* BR (opt) */
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2842 ws[wpos] = '\n';
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2843 wpos++;
10217
0ba0263c657f [gaim-migrate @ 11345]
Daniel Westermann-Clark
parents: 10184
diff changeset
2844 br = TRUE;
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents: 6882
diff changeset
2845 break;
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2846 case 26: /* HR */
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2847 case 42: /* HR (opt) */
8726
3db8ac8e0ebb [gaim-migrate @ 9481]
Tim Ringenbach <marv@pidgin.im>
parents: 8719
diff changeset
2848 {
3db8ac8e0ebb [gaim-migrate @ 9481]
Tim Ringenbach <marv@pidgin.im>
parents: 8719
diff changeset
2849 int minus;
11224
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
2850 struct scalable_data *sd = g_new(struct scalable_data, 1);
8726
3db8ac8e0ebb [gaim-migrate @ 9481]
Tim Ringenbach <marv@pidgin.im>
parents: 8719
diff changeset
2851
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2852 ws[wpos++] = '\n';
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2853 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2854
11224
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
2855 sd->scalable = scalable = gtk_imhtml_hr_new();
11233
28c0f184a2d4 [gaim-migrate @ 13373]
Daniel Atallah <datallah@pidgin.im>
parents: 11224
diff changeset
2856 sd->mark = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, iter, TRUE);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2857 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2858 scalable->add_to(scalable, imhtml, iter);
8726
3db8ac8e0ebb [gaim-migrate @ 9481]
Tim Ringenbach <marv@pidgin.im>
parents: 8719
diff changeset
2859 minus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(imhtml)) +
3db8ac8e0ebb [gaim-migrate @ 9481]
Tim Ringenbach <marv@pidgin.im>
parents: 8719
diff changeset
2860 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(imhtml));
3db8ac8e0ebb [gaim-migrate @ 9481]
Tim Ringenbach <marv@pidgin.im>
parents: 8719
diff changeset
2861 scalable->scale(scalable, rect.width - minus, rect.height);
11224
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
2862 imhtml->scalables = g_list_append(imhtml->scalables, sd);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2863 ws[0] = '\0'; wpos = 0;
7942
e6c3c6ab87af [gaim-migrate @ 8613]
Ka-Hing Cheung <khc@pidgin.im>
parents: 7914
diff changeset
2864 ws[wpos++] = '\n';
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2865
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2866 break;
8726
3db8ac8e0ebb [gaim-migrate @ 9481]
Tim Ringenbach <marv@pidgin.im>
parents: 8719
diff changeset
2867 }
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2868 case 27: /* /FONT */
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2869 if (fonts && !imhtml->wbfo) {
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
2870 GtkIMHtmlFontDetail *font = fonts->data;
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2871 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2872 ws[0] = '\0'; wpos = 0;
8177
33b3a01c6318 [gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents: 8149
diff changeset
2873 /* NEW_BIT (NEW_TEXT_BIT); */
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2874
8698
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
2875 if (font->face && (imhtml->format_functions & GTK_IMHTML_FACE)) {
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2876 gtk_imhtml_toggle_fontface(imhtml, NULL);
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2877 }
14821
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
2878 g_free (font->face);
8698
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
2879 if (font->fore && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) {
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2880 gtk_imhtml_toggle_forecolor(imhtml, NULL);
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2881 }
14821
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
2882 g_free (font->fore);
8698
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
2883 if (font->back && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) {
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2884 gtk_imhtml_toggle_backcolor(imhtml, NULL);
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2885 }
14821
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
2886 g_free (font->back);
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
2887 g_free (font->sml);
8309
f9db944d6b6c [gaim-migrate @ 9033]
Sean Egan <seanegan@pidgin.im>
parents: 8250
diff changeset
2888
8698
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
2889 if ((font->size != 3) && (imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK)))
8309
f9db944d6b6c [gaim-migrate @ 9033]
Sean Egan <seanegan@pidgin.im>
parents: 8250
diff changeset
2890 gtk_imhtml_font_set_size(imhtml, 3);
f9db944d6b6c [gaim-migrate @ 9033]
Sean Egan <seanegan@pidgin.im>
parents: 8250
diff changeset
2891
10761
cbfb52c33913 [gaim-migrate @ 12365]
Nathan Walp <nwalp@pidgin.im>
parents: 10732
diff changeset
2892 fonts = g_slist_remove (fonts, font);
9245
733eb4d721f7 [gaim-migrate @ 10044]
Tim Ringenbach <marv@pidgin.im>
parents: 9229
diff changeset
2893 g_free(font);
733eb4d721f7 [gaim-migrate @ 10044]
Tim Ringenbach <marv@pidgin.im>
parents: 9229
diff changeset
2894
8309
f9db944d6b6c [gaim-migrate @ 9033]
Sean Egan <seanegan@pidgin.im>
parents: 8250
diff changeset
2895 if (fonts) {
f9db944d6b6c [gaim-migrate @ 9033]
Sean Egan <seanegan@pidgin.im>
parents: 8250
diff changeset
2896 GtkIMHtmlFontDetail *font = fonts->data;
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2897
8698
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
2898 if (font->face && (imhtml->format_functions & GTK_IMHTML_FACE))
8309
f9db944d6b6c [gaim-migrate @ 9033]
Sean Egan <seanegan@pidgin.im>
parents: 8250
diff changeset
2899 gtk_imhtml_toggle_fontface(imhtml, font->face);
8698
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
2900 if (font->fore && (imhtml->format_functions & GTK_IMHTML_FORECOLOR))
8309
f9db944d6b6c [gaim-migrate @ 9033]
Sean Egan <seanegan@pidgin.im>
parents: 8250
diff changeset
2901 gtk_imhtml_toggle_forecolor(imhtml, font->fore);
8698
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
2902 if (font->back && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR))
8309
f9db944d6b6c [gaim-migrate @ 9033]
Sean Egan <seanegan@pidgin.im>
parents: 8250
diff changeset
2903 gtk_imhtml_toggle_backcolor(imhtml, font->back);
8698
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
2904 if ((font->size != 3) && (imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK)))
8309
f9db944d6b6c [gaim-migrate @ 9033]
Sean Egan <seanegan@pidgin.im>
parents: 8250
diff changeset
2905 gtk_imhtml_font_set_size(imhtml, font->size);
f9db944d6b6c [gaim-migrate @ 9033]
Sean Egan <seanegan@pidgin.im>
parents: 8250
diff changeset
2906 }
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2907 }
8309
f9db944d6b6c [gaim-migrate @ 9033]
Sean Egan <seanegan@pidgin.im>
parents: 8250
diff changeset
2908 break;
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2909 case 28: /* /A */
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2910 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2911 gtk_imhtml_toggle_link(imhtml, NULL);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2912 ws[0] = '\0'; wpos = 0;
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2913 break;
8118
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
2914
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2915 case 29: /* P */
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2916 case 30: /* /P */
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2917 case 31: /* H3 */
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2918 case 32: /* /H3 */
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2919 case 33: /* HTML */
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2920 case 34: /* /HTML */
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2921 case 35: /* BODY */
10776
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
2922 break;
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2923 case 36: /* /BODY */
10786
ccd157c17483 [gaim-migrate @ 12426]
Tim Ringenbach <marv@pidgin.im>
parents: 10782
diff changeset
2924 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
ccd157c17483 [gaim-migrate @ 12426]
Tim Ringenbach <marv@pidgin.im>
parents: 10782
diff changeset
2925 ws[0] = '\0'; wpos = 0;
10776
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
2926 gtk_imhtml_toggle_background(imhtml, NULL);
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
2927 break;
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2928 case 37: /* FONT */
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2929 case 38: /* HEAD */
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2930 case 39: /* /HEAD */
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents: 6882
diff changeset
2931 case 40: /* BINARY */
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents: 6882
diff changeset
2932 case 41: /* /BINARY */
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2933 break;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2934 case 43: /* FONT (opt) */
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2935 {
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2936 gchar *color, *back, *face, *size, *sml;
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
2937 GtkIMHtmlFontDetail *font, *oldfont = NULL;
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2938 color = gtk_imhtml_get_html_opt (tag, "COLOR=");
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2939 back = gtk_imhtml_get_html_opt (tag, "BACK=");
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2940 face = gtk_imhtml_get_html_opt (tag, "FACE=");
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2941 size = gtk_imhtml_get_html_opt (tag, "SIZE=");
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2942 sml = gtk_imhtml_get_html_opt (tag, "SML=");
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2943 if (!(color || back || face || size || sml))
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2944 break;
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2945
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2946 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2947 ws[0] = '\0'; wpos = 0;
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2948
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
2949 font = g_new0 (GtkIMHtmlFontDetail, 1);
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2950 if (fonts)
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2951 oldfont = fonts->data;
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
2952
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2953 if (color && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) {
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2954 font->fore = color;
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2955 gtk_imhtml_toggle_forecolor(imhtml, font->fore);
14821
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
2956 } else
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
2957 g_free(color);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2958
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2959 if (back && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) {
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2960 font->back = back;
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2961 gtk_imhtml_toggle_backcolor(imhtml, font->back);
14821
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
2962 } else
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
2963 g_free(back);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2964
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2965 if (face && !(options & GTK_IMHTML_NO_FONTS) && (imhtml->format_functions & GTK_IMHTML_FACE)) {
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2966 font->face = face;
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
2967 gtk_imhtml_toggle_fontface(imhtml, font->face);
14821
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
2968 } else
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
2969 g_free(face);
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2970
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2971 if (sml)
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2972 font->sml = sml;
22810
ede0b51be7c3 Patch from Gaul to plug a small leak, with an additional fix to free
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22803
diff changeset
2973 else {
ede0b51be7c3 Patch from Gaul to plug a small leak, with an additional fix to free
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22803
diff changeset
2974 g_free(sml);
ede0b51be7c3 Patch from Gaul to plug a small leak, with an additional fix to free
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22803
diff changeset
2975 if (oldfont && oldfont->sml)
ede0b51be7c3 Patch from Gaul to plug a small leak, with an additional fix to free
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22803
diff changeset
2976 font->sml = g_strdup(oldfont->sml);
ede0b51be7c3 Patch from Gaul to plug a small leak, with an additional fix to free
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22803
diff changeset
2977 }
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
2978
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
2979 if (size && !(options & GTK_IMHTML_NO_SIZES) && (imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) {
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2980 if (*size == '+') {
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2981 sscanf (size + 1, "%hd", &font->size);
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2982 font->size += 3;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2983 } else if (*size == '-') {
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2984 sscanf (size + 1, "%hd", &font->size);
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2985 font->size = MAX (0, 3 - font->size);
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2986 } else if (isdigit (*size)) {
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2987 sscanf (size, "%hd", &font->size);
14821
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
2988 }
6042
e329fe962c9a [gaim-migrate @ 6492]
Mark Doliner <markdoliner@pidgin.im>
parents: 5967
diff changeset
2989 if (font->size > 100)
e329fe962c9a [gaim-migrate @ 6492]
Mark Doliner <markdoliner@pidgin.im>
parents: 5967
diff changeset
2990 font->size = 100;
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2991 } else if (oldfont)
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2992 font->size = oldfont->size;
8309
f9db944d6b6c [gaim-migrate @ 9033]
Sean Egan <seanegan@pidgin.im>
parents: 8250
diff changeset
2993 else
f9db944d6b6c [gaim-migrate @ 9033]
Sean Egan <seanegan@pidgin.im>
parents: 8250
diff changeset
2994 font->size = 3;
28144
fd25bc3ab207 imhtml: When inserting html, only set a font if it's a change from the default. Fixes #7648.
Paul Aurich <darkrain42@pidgin.im>
parents: 28077
diff changeset
2995 if ((imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK)) && (font->size != 3 || (oldfont && oldfont->size == 3)))
8698
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
2996 gtk_imhtml_font_set_size(imhtml, font->size);
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2997 g_free(size);
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2998 fonts = g_slist_prepend (fonts, font);
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
2999 }
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
3000 break;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
3001 case 44: /* BODY (opt) */
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
3002 if (!(options & GTK_IMHTML_NO_COLOURS)) {
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
3003 char *bgcolor = gtk_imhtml_get_html_opt (tag, "BGCOLOR=");
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
3004 if (bgcolor && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
3005 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3006 ws[0] = '\0'; wpos = 0;
8177
33b3a01c6318 [gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents: 8149
diff changeset
3007 /* NEW_BIT(NEW_TEXT_BIT); */
14097
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 14010
diff changeset
3008 g_free(bg);
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
3009 bg = bgcolor;
10776
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
3010 gtk_imhtml_toggle_background(imhtml, bg);
14821
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
3011 } else
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
3012 g_free(bgcolor);
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
3013 }
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
3014 break;
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
3015 case 45: /* A (opt) */
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
3016 {
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
3017 gchar *href = gtk_imhtml_get_html_opt (tag, "HREF=");
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
3018 if (href && (imhtml->format_functions & GTK_IMHTML_LINK)) {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
3019 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3020 ws[0] = '\0'; wpos = 0;
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
3021 gtk_imhtml_toggle_link(imhtml, href);
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
3022 }
14097
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 14010
diff changeset
3023 g_free(href);
2993
0340d0a8b810 [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
3024 }
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
3025 break;
4895
51794f61995e [gaim-migrate @ 5227]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4892
diff changeset
3026 case 46: /* IMG (opt) */
6982
12f08de92674 [gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents: 6882
diff changeset
3027 case 59: /* IMG */
4895
51794f61995e [gaim-migrate @ 5227]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4892
diff changeset
3028 {
22810
ede0b51be7c3 Patch from Gaul to plug a small leak, with an additional fix to free
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22803
diff changeset
3029 char *id;
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
3030
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
3031 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
3032 ws[0] = '\0'; wpos = 0;
4895
51794f61995e [gaim-migrate @ 5227]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4892
diff changeset
3033
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
3034 if (!(imhtml->format_functions & GTK_IMHTML_IMAGE))
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
3035 break;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
3036
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
3037 id = gtk_imhtml_get_html_opt(tag, "ID=");
27359
3d884bc7b99e Transform id-less <img> tags to links using src and alt attributes.
Dmitry Petroff <dmitry.petroff@gmail.com>
parents: 27259
diff changeset
3038 if (id) {
3d884bc7b99e Transform id-less <img> tags to links using src and alt attributes.
Dmitry Petroff <dmitry.petroff@gmail.com>
parents: 27259
diff changeset
3039 gtk_imhtml_insert_image_at_iter(imhtml, atoi(id), iter);
3d884bc7b99e Transform id-less <img> tags to links using src and alt attributes.
Dmitry Petroff <dmitry.petroff@gmail.com>
parents: 27259
diff changeset
3040 g_free(id);
3d884bc7b99e Transform id-less <img> tags to links using src and alt attributes.
Dmitry Petroff <dmitry.petroff@gmail.com>
parents: 27259
diff changeset
3041 } else {
3d884bc7b99e Transform id-less <img> tags to links using src and alt attributes.
Dmitry Petroff <dmitry.petroff@gmail.com>
parents: 27259
diff changeset
3042 char *src, *alt;
3d884bc7b99e Transform id-less <img> tags to links using src and alt attributes.
Dmitry Petroff <dmitry.petroff@gmail.com>
parents: 27259
diff changeset
3043 src = gtk_imhtml_get_html_opt(tag, "SRC=");
3d884bc7b99e Transform id-less <img> tags to links using src and alt attributes.
Dmitry Petroff <dmitry.petroff@gmail.com>
parents: 27259
diff changeset
3044 alt = gtk_imhtml_get_html_opt(tag, "ALT=");
3d884bc7b99e Transform id-less <img> tags to links using src and alt attributes.
Dmitry Petroff <dmitry.petroff@gmail.com>
parents: 27259
diff changeset
3045 if (src) {
3d884bc7b99e Transform id-less <img> tags to links using src and alt attributes.
Dmitry Petroff <dmitry.petroff@gmail.com>
parents: 27259
diff changeset
3046 gtk_imhtml_toggle_link(imhtml, src);
3d884bc7b99e Transform id-less <img> tags to links using src and alt attributes.
Dmitry Petroff <dmitry.petroff@gmail.com>
parents: 27259
diff changeset
3047 gtk_text_buffer_insert(imhtml->text_buffer, iter, alt ? alt : src, -1);
3d884bc7b99e Transform id-less <img> tags to links using src and alt attributes.
Dmitry Petroff <dmitry.petroff@gmail.com>
parents: 27259
diff changeset
3048 gtk_imhtml_toggle_link(imhtml, NULL);
3d884bc7b99e Transform id-less <img> tags to links using src and alt attributes.
Dmitry Petroff <dmitry.petroff@gmail.com>
parents: 27259
diff changeset
3049 }
3d884bc7b99e Transform id-less <img> tags to links using src and alt attributes.
Dmitry Petroff <dmitry.petroff@gmail.com>
parents: 27259
diff changeset
3050 g_free (src);
3d884bc7b99e Transform id-less <img> tags to links using src and alt attributes.
Dmitry Petroff <dmitry.petroff@gmail.com>
parents: 27259
diff changeset
3051 g_free (alt);
3d884bc7b99e Transform id-less <img> tags to links using src and alt attributes.
Dmitry Petroff <dmitry.petroff@gmail.com>
parents: 27259
diff changeset
3052 }
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
3053 break;
4895
51794f61995e [gaim-migrate @ 5227]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4892
diff changeset
3054 }
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
3055 case 47: /* P (opt) */
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
3056 case 48: /* H3 (opt) */
5093
7761492245e6 [gaim-migrate @ 5455]
Nathan Walp <nwalp@pidgin.im>
parents: 5091
diff changeset
3057 case 49: /* HTML (opt) */
5101
b771f92a4f10 [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
3058 case 50: /* CITE */
b771f92a4f10 [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
3059 case 51: /* /CITE */
8026
91fe30ffb897 [gaim-migrate @ 8706]
Nathan Walp <nwalp@pidgin.im>
parents: 7991
diff changeset
3060 case 56: /* SPAN (opt) */
8118
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3061 /* Inline CSS Support - Douglas Thrift
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3062 *
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3063 * color
8686
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3064 * background
8118
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3065 * font-family
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3066 * font-size
8686
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3067 * text-decoration: underline
14395
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3068 * font-weight: bold
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3069 * direction: rtl
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3070 * text-align: right
10483
e7b09a8b1f52 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10457
diff changeset
3071 *
e7b09a8b1f52 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10457
diff changeset
3072 * TODO:
e7b09a8b1f52 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10457
diff changeset
3073 * background-color
e7b09a8b1f52 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10457
diff changeset
3074 * font-style
8118
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3075 */
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3076 {
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3077 gchar *style, *color, *background, *family, *size, *direction, *alignment;
14395
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3078 gchar *textdec, *weight;
8118
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3079 GtkIMHtmlFontDetail *font, *oldfont = NULL;
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3080 style = gtk_imhtml_get_html_opt (tag, "style=");
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3081
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3082 if (!style) break;
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3083
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3084 color = purple_markup_get_css_property (style, "color");
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3085 background = purple_markup_get_css_property (style, "background");
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3086 family = purple_markup_get_css_property (style, "font-family");
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3087 size = purple_markup_get_css_property (style, "font-size");
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3088 textdec = purple_markup_get_css_property (style, "text-decoration");
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3089 weight = purple_markup_get_css_property (style, "font-weight");
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3090 direction = purple_markup_get_css_property (style, "direction");
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3091 alignment = purple_markup_get_css_property (style, "text-align");
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3092
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3093
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3094 if (!(color || family || size || background || textdec || weight || direction || alignment)) {
8120
d26183feb7e4 [gaim-migrate @ 8824]
Nathan Walp <nwalp@pidgin.im>
parents: 8118
diff changeset
3095 g_free(style);
d26183feb7e4 [gaim-migrate @ 8824]
Nathan Walp <nwalp@pidgin.im>
parents: 8118
diff changeset
3096 break;
d26183feb7e4 [gaim-migrate @ 8824]
Nathan Walp <nwalp@pidgin.im>
parents: 8118
diff changeset
3097 }
8118
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3098
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
3099
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
3100 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8118
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3101 ws[0] = '\0'; wpos = 0;
8177
33b3a01c6318 [gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents: 8149
diff changeset
3102 /* NEW_BIT (NEW_TEXT_BIT); */
8118
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3103
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3104 /* Bi-Directional text support */
18552
810a338ef085 Use the glib strcasecmp functions everywhere, as we've had reports of
Richard Laager <rlaager@pidgin.im>
parents: 18543
diff changeset
3105 if (direction && (!g_ascii_strncasecmp(direction, "RTL", 3))) {
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3106 rtl_direction = TRUE;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3107 /* insert RLE character to set direction */
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3108 ws[wpos++] = 0xE2;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3109 ws[wpos++] = 0x80;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3110 ws[wpos++] = 0xAB;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3111 ws[wpos] = '\0';
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3112 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3113 ws[0] = '\0'; wpos = 0;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3114 }
16144
4e022531d1c9 Patch cleanups:
Richard Laager <rlaager@pidgin.im>
parents: 16143
diff changeset
3115 g_free(direction);
4e022531d1c9 Patch cleanups:
Richard Laager <rlaager@pidgin.im>
parents: 16143
diff changeset
3116
18552
810a338ef085 Use the glib strcasecmp functions everywhere, as we've had reports of
Richard Laager <rlaager@pidgin.im>
parents: 18543
diff changeset
3117 if (alignment && (!g_ascii_strncasecmp(alignment, "RIGHT", 5))) {
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3118 align_right = TRUE;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3119 align_line = gtk_text_iter_get_line(iter);
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3120 }
16144
4e022531d1c9 Patch cleanups:
Richard Laager <rlaager@pidgin.im>
parents: 16143
diff changeset
3121 g_free(alignment);
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3122
8118
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3123 font = g_new0 (GtkIMHtmlFontDetail, 1);
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3124 if (fonts)
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3125 oldfont = fonts->data;
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3126
14821
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
3127 if (color && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) {
24509
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
3128 font->fore = parse_css_color(color);
8686
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3129 gtk_imhtml_toggle_forecolor(imhtml, font->fore);
14821
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
3130 } else {
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
3131 if (oldfont && oldfont->fore)
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
3132 font->fore = g_strdup(oldfont->fore);
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
3133 g_free(color);
8686
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3134 }
14821
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
3135
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
3136 if (background && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) {
24509
afdf30801940 Support rgb(r,g,b) style css color definitions. Fixes #7288.
Daniel Atallah <datallah@pidgin.im>
parents: 24392
diff changeset
3137 font->back = parse_css_color(background);
8686
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3138 gtk_imhtml_toggle_backcolor(imhtml, font->back);
14821
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
3139 } else {
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
3140 if (oldfont && oldfont->back)
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
3141 font->back = g_strdup(oldfont->back);
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
3142 g_free(background);
8686
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3143 }
14821
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
3144
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
3145 if (family && !(options & GTK_IMHTML_NO_FONTS) && (imhtml->format_functions & GTK_IMHTML_FACE)) {
8118
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3146 font->face = family;
8686
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3147 gtk_imhtml_toggle_fontface(imhtml, font->face);
14821
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
3148 } else {
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
3149 if (oldfont && oldfont->face)
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
3150 font->face = g_strdup(oldfont->face);
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
3151 g_free(family);
8686
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3152 }
8118
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3153 if (font->face && (atoi(font->face) > 100)) {
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
3154 /* WTF is this? */
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
3155 /* Maybe it sets a max size on the font face? I seem to
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
3156 * remember bad things happening if the font size was
9696
9d62e1ec5977 [gaim-migrate @ 10555]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 9636
diff changeset
3157 * 2 billion */
8118
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3158 g_free(font->face);
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3159 font->face = g_strdup("100");
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3160 }
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3161
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3162 if (oldfont && oldfont->sml)
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3163 font->sml = g_strdup(oldfont->sml);
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3164
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
3165 if (size && !(options & GTK_IMHTML_NO_SIZES) && (imhtml->format_functions & (GTK_IMHTML_SHRINK|GTK_IMHTML_GROW))) {
8686
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3166 if (g_ascii_strcasecmp(size, "xx-small") == 0)
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3167 font->size = 1;
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3168 else if (g_ascii_strcasecmp(size, "smaller") == 0
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3169 || g_ascii_strcasecmp(size, "x-small") == 0)
8118
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3170 font->size = 2;
25299
82d682722b68 Change our font mapping in gtkimhtml to match the suggested values
Mark Doliner <markdoliner@pidgin.im>
parents: 25168
diff changeset
3171 else if (g_ascii_strcasecmp(size, "medium") == 0)
82d682722b68 Change our font mapping in gtkimhtml to match the suggested values
Mark Doliner <markdoliner@pidgin.im>
parents: 25168
diff changeset
3172 font->size = 3;
82d682722b68 Change our font mapping in gtkimhtml to match the suggested values
Mark Doliner <markdoliner@pidgin.im>
parents: 25168
diff changeset
3173 else if (g_ascii_strcasecmp(size, "large") == 0
82d682722b68 Change our font mapping in gtkimhtml to match the suggested values
Mark Doliner <markdoliner@pidgin.im>
parents: 25168
diff changeset
3174 || g_ascii_strcasecmp(size, "larger") == 0)
8118
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3175 font->size = 4;
25299
82d682722b68 Change our font mapping in gtkimhtml to match the suggested values
Mark Doliner <markdoliner@pidgin.im>
parents: 25168
diff changeset
3176 else if (g_ascii_strcasecmp(size, "x-large") == 0)
8686
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3177 font->size = 5;
25299
82d682722b68 Change our font mapping in gtkimhtml to match the suggested values
Mark Doliner <markdoliner@pidgin.im>
parents: 25168
diff changeset
3178 else if (g_ascii_strcasecmp(size, "xx-large") == 0)
8686
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3179 font->size = 6;
25168
4f508dba5218 Change the way we handle <span style='font-size: whatever;'> tags slightly.
Mark Doliner <markdoliner@pidgin.im>
parents: 24588
diff changeset
3180
4f508dba5218 Change the way we handle <span style='font-size: whatever;'> tags slightly.
Mark Doliner <markdoliner@pidgin.im>
parents: 24588
diff changeset
3181 /*
4f508dba5218 Change the way we handle <span style='font-size: whatever;'> tags slightly.
Mark Doliner <markdoliner@pidgin.im>
parents: 24588
diff changeset
3182 * TODO: Handle other values, like percentages, or
4f508dba5218 Change the way we handle <span style='font-size: whatever;'> tags slightly.
Mark Doliner <markdoliner@pidgin.im>
parents: 24588
diff changeset
3183 * lengths specified as em, ex, px, in, cm, mm, pt
4f508dba5218 Change the way we handle <span style='font-size: whatever;'> tags slightly.
Mark Doliner <markdoliner@pidgin.im>
parents: 24588
diff changeset
3184 * or pc. Or even better, use an actual HTML
4f508dba5218 Change the way we handle <span style='font-size: whatever;'> tags slightly.
Mark Doliner <markdoliner@pidgin.im>
parents: 24588
diff changeset
3185 * renderer like webkit.
4f508dba5218 Change the way we handle <span style='font-size: whatever;'> tags slightly.
Mark Doliner <markdoliner@pidgin.im>
parents: 24588
diff changeset
3186 */
4f508dba5218 Change the way we handle <span style='font-size: whatever;'> tags slightly.
Mark Doliner <markdoliner@pidgin.im>
parents: 24588
diff changeset
3187 if (font->size > 0)
4f508dba5218 Change the way we handle <span style='font-size: whatever;'> tags slightly.
Mark Doliner <markdoliner@pidgin.im>
parents: 24588
diff changeset
3188 gtk_imhtml_font_set_size(imhtml, font->size);
8686
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3189 }
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3190 else if (oldfont)
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3191 {
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3192 font->size = oldfont->size;
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3193 }
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3194
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3195 if (oldfont)
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3196 {
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3197 font->underline = oldfont->underline;
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3198 }
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3199 if (textdec && font->underline != 1
9025
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
3200 && g_ascii_strcasecmp(textdec, "underline") == 0
17088
1ecea6e2fd97 Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17009
diff changeset
3201 && (imhtml->format_functions & GTK_IMHTML_UNDERLINE)
1ecea6e2fd97 Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17009
diff changeset
3202 && !(options & GTK_IMHTML_NO_FORMATTING))
8686
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3203 {
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3204 gtk_imhtml_toggle_underline(imhtml);
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3205 font->underline = 1;
21425
9a163ab7adb1 Another leak fix.
Daniel Atallah <datallah@pidgin.im>
parents: 21128
diff changeset
3206 }
9a163ab7adb1 Another leak fix.
Daniel Atallah <datallah@pidgin.im>
parents: 21128
diff changeset
3207 g_free(textdec);
8118
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3208
14395
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3209 if (oldfont)
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3210 {
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3211 font->bold = oldfont->bold;
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3212 }
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3213 if (weight)
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3214 {
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3215 if(!g_ascii_strcasecmp(weight, "normal")) {
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3216 font->bold = 0;
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3217 } else if(!g_ascii_strcasecmp(weight, "bold")) {
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3218 font->bold = 1;
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3219 } else if(!g_ascii_strcasecmp(weight, "bolder")) {
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3220 font->bold++;
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3221 } else if(!g_ascii_strcasecmp(weight, "lighter")) {
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3222 if(font->bold > 0)
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3223 font->bold--;
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3224 } else {
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3225 int num = atoi(weight);
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3226 if(num >= 700)
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3227 font->bold = 1;
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3228 else
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3229 font->bold = 0;
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3230 }
17088
1ecea6e2fd97 Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17009
diff changeset
3231 if (((font->bold && oldfont && !oldfont->bold) || (oldfont && oldfont->bold && !font->bold) || (font->bold && !oldfont)) && !(options & GTK_IMHTML_NO_FORMATTING))
14395
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3232 {
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3233 gtk_imhtml_toggle_bold(imhtml);
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3234 }
14821
c91127e2b784 [gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14741
diff changeset
3235 g_free(weight);
14395
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3236 }
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3237
8118
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3238 g_free(style);
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3239 g_free(size);
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3240 fonts = g_slist_prepend (fonts, font);
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3241 }
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3242 break;
5104
2a09bf67e875 [gaim-migrate @ 5467]
Nathan Walp <nwalp@pidgin.im>
parents: 5101
diff changeset
3243 case 57: /* /SPAN */
8118
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3244 /* Inline CSS Support - Douglas Thrift */
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
3245 if (fonts && !imhtml->wbfo) {
8686
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3246 GtkIMHtmlFontDetail *oldfont = NULL;
8118
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3247 GtkIMHtmlFontDetail *font = fonts->data;
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
3248 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8118
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3249 ws[0] = '\0'; wpos = 0;
8177
33b3a01c6318 [gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents: 8149
diff changeset
3250 /* NEW_BIT (NEW_TEXT_BIT); */
8118
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3251 fonts = g_slist_remove (fonts, font);
8692
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
3252 if (fonts)
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
3253 oldfont = fonts->data;
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
3254
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
3255 if (!oldfont) {
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
3256 gtk_imhtml_font_set_size(imhtml, 3);
17088
1ecea6e2fd97 Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17009
diff changeset
3257 if (font->underline && !(options & GTK_IMHTML_NO_FORMATTING))
8692
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
3258 gtk_imhtml_toggle_underline(imhtml);
17088
1ecea6e2fd97 Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17009
diff changeset
3259 if (font->bold && !(options & GTK_IMHTML_NO_FORMATTING))
14395
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3260 gtk_imhtml_toggle_bold(imhtml);
17088
1ecea6e2fd97 Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17009
diff changeset
3261 if (!(options & GTK_IMHTML_NO_FONTS))
1ecea6e2fd97 Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17009
diff changeset
3262 gtk_imhtml_toggle_fontface(imhtml, NULL);
1ecea6e2fd97 Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17009
diff changeset
3263 if (!(options & GTK_IMHTML_NO_COLOURS))
1ecea6e2fd97 Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17009
diff changeset
3264 gtk_imhtml_toggle_forecolor(imhtml, NULL);
1ecea6e2fd97 Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17009
diff changeset
3265 if (!(options & GTK_IMHTML_NO_COLOURS))
1ecea6e2fd97 Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17009
diff changeset
3266 gtk_imhtml_toggle_backcolor(imhtml, NULL);
8686
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3267 }
8692
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
3268 else
8686
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3269 {
8692
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
3270
17088
1ecea6e2fd97 Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17009
diff changeset
3271 if ((font->size != oldfont->size) && !(options & GTK_IMHTML_NO_SIZES))
8692
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
3272 gtk_imhtml_font_set_size(imhtml, oldfont->size);
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
3273
17088
1ecea6e2fd97 Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17009
diff changeset
3274 if ((font->underline != oldfont->underline) && !(options & GTK_IMHTML_NO_FORMATTING))
8692
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
3275 gtk_imhtml_toggle_underline(imhtml);
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
3276
17088
1ecea6e2fd97 Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17009
diff changeset
3277 if (((font->bold && !oldfont->bold) || (oldfont->bold && !font->bold)) && !(options & GTK_IMHTML_NO_FORMATTING))
14395
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3278 gtk_imhtml_toggle_bold(imhtml);
cf8c889161ff [gaim-migrate @ 17029]
Nathan Walp <nwalp@pidgin.im>
parents: 14253
diff changeset
3279
17088
1ecea6e2fd97 Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17009
diff changeset
3280 if (font->face && (!oldfont->face || strcmp(font->face, oldfont->face) != 0) && !(options & GTK_IMHTML_NO_FONTS))
8692
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
3281 gtk_imhtml_toggle_fontface(imhtml, oldfont->face);
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
3282
17088
1ecea6e2fd97 Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17009
diff changeset
3283 if (font->fore && (!oldfont->fore || strcmp(font->fore, oldfont->fore) != 0) && !(options & GTK_IMHTML_NO_COLOURS))
8692
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
3284 gtk_imhtml_toggle_forecolor(imhtml, oldfont->fore);
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
3285
17088
1ecea6e2fd97 Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 17009
diff changeset
3286 if (font->back && (!oldfont->back || strcmp(font->back, oldfont->back) != 0) && !(options & GTK_IMHTML_NO_COLOURS))
8692
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
3287 gtk_imhtml_toggle_backcolor(imhtml, oldfont->back);
8686
87eb1cde44c9 [gaim-migrate @ 9439]
Kevin Stange <kstange@pidgin.im>
parents: 8681
diff changeset
3288 }
8692
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
3289
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
3290 g_free (font->face);
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
3291 g_free (font->fore);
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
3292 g_free (font->back);
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
3293 g_free (font->sml);
d93813239791 [gaim-migrate @ 9445]
Kevin Stange <kstange@pidgin.im>
parents: 8686
diff changeset
3294
8118
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3295 g_free (font);
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3296 }
7f5315bb4506 [gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents: 8105
diff changeset
3297 break;
8026
91fe30ffb897 [gaim-migrate @ 8706]
Nathan Walp <nwalp@pidgin.im>
parents: 7991
diff changeset
3298 case 60: /* SPAN */
2993
0340d0a8b810 [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
3299 break;
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3300 case 62: /* comment */
8177
33b3a01c6318 [gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents: 8149
diff changeset
3301 /* NEW_BIT (NEW_TEXT_BIT); */
8317
fd4cf67705df [gaim-migrate @ 9041]
Sean Egan <seanegan@pidgin.im>
parents: 8309
diff changeset
3302 ws[wpos] = '\0';
9465
652dcd45db7d [gaim-migrate @ 10290]
Tim Ringenbach <marv@pidgin.im>
parents: 9337
diff changeset
3303
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
3304 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
3305
22486
e77232ab761f Disable invisible text things, if someone can conclusively prove this is
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 22276
diff changeset
3306 #if FALSE && GTK_CHECK_VERSION(2,10,10)
22211
7f3cecdb079c disapproval of revision '2c96f5a301400781ce5fbf144ffdbae44f895281'
Sean Egan <seanegan@pidgin.im>
parents: 22210
diff changeset
3307 wpos = g_snprintf (ws, len, "%s", tag);
7f3cecdb079c disapproval of revision '2c96f5a301400781ce5fbf144ffdbae44f895281'
Sean Egan <seanegan@pidgin.im>
parents: 22210
diff changeset
3308 gtk_text_buffer_insert_with_tags_by_name(imhtml->text_buffer, iter, ws, wpos, "comment", NULL);
7f3cecdb079c disapproval of revision '2c96f5a301400781ce5fbf144ffdbae44f895281'
Sean Egan <seanegan@pidgin.im>
parents: 22210
diff changeset
3309 #else
10815
b1ca28de65d3 [gaim-migrate @ 12470]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10814
diff changeset
3310 if (imhtml->show_comments && !(options & GTK_IMHTML_NO_COMMENTS)) {
6124
322206d79652 [gaim-migrate @ 6598]
Mark Doliner <markdoliner@pidgin.im>
parents: 6066
diff changeset
3311 wpos = g_snprintf (ws, len, "%s", tag);
23308
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
3312 gtk_text_buffer_insert_with_tags_by_name(imhtml->text_buffer, iter, ws, wpos, "comment", NULL);
10815
b1ca28de65d3 [gaim-migrate @ 12470]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10814
diff changeset
3313 }
22211
7f3cecdb079c disapproval of revision '2c96f5a301400781ce5fbf144ffdbae44f895281'
Sean Egan <seanegan@pidgin.im>
parents: 22210
diff changeset
3314 #endif
10815
b1ca28de65d3 [gaim-migrate @ 12470]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10814
diff changeset
3315 ws[0] = '\0'; wpos = 0;
b1ca28de65d3 [gaim-migrate @ 12470]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10814
diff changeset
3316
8177
33b3a01c6318 [gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents: 8149
diff changeset
3317 /* NEW_BIT (NEW_COMMENT_BIT); */
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
3318 break;
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
3319 default:
6882
b6d0ac441869 [gaim-migrate @ 7428]
Tim Ringenbach <marv@pidgin.im>
parents: 6839
diff changeset
3320 break;
2993
0340d0a8b810 [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
3321 }
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
3322 c += tlen;
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
3323 pos += tlen;
13138
4d3bd039da3e [gaim-migrate @ 15499]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13137
diff changeset
3324 g_free(tag); /* This was allocated back in VALID_TAG() */
15331
a8ef18791524 [gaim-migrate @ 18059]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15111
diff changeset
3325 } else if (imhtml->edit.link == NULL &&
22003
904ebe8d6058 Patch from 'goutnet' to not insert smileys when pasting as plain text.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21765
diff changeset
3326 !(options & GTK_IMHTML_NO_SMILEY) &&
15331
a8ef18791524 [gaim-migrate @ 18059]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15111
diff changeset
3327 gtk_imhtml_is_smiley(imhtml, fonts, c, &smilelen)) {
8473
8acf91aaffac [gaim-migrate @ 9206]
Kevin Stange <kstange@pidgin.im>
parents: 8466
diff changeset
3328 GtkIMHtmlFontDetail *fd;
8acf91aaffac [gaim-migrate @ 9206]
Kevin Stange <kstange@pidgin.im>
parents: 8466
diff changeset
3329 gchar *sml = NULL;
21574
b27c242d1288 Fix #3930 by correctly detecting when we're no longer immediately following a br.
Daniel Atallah <datallah@pidgin.im>
parents: 21425
diff changeset
3330
b27c242d1288 Fix #3930 by correctly detecting when we're no longer immediately following a br.
Daniel Atallah <datallah@pidgin.im>
parents: 21425
diff changeset
3331 br = FALSE;
b27c242d1288 Fix #3930 by correctly detecting when we're no longer immediately following a br.
Daniel Atallah <datallah@pidgin.im>
parents: 21425
diff changeset
3332
8473
8acf91aaffac [gaim-migrate @ 9206]
Kevin Stange <kstange@pidgin.im>
parents: 8466
diff changeset
3333 if (fonts) {
8acf91aaffac [gaim-migrate @ 9206]
Kevin Stange <kstange@pidgin.im>
parents: 8466
diff changeset
3334 fd = fonts->data;
8acf91aaffac [gaim-migrate @ 9206]
Kevin Stange <kstange@pidgin.im>
parents: 8466
diff changeset
3335 sml = fd->sml;
8acf91aaffac [gaim-migrate @ 9206]
Kevin Stange <kstange@pidgin.im>
parents: 8466
diff changeset
3336 }
9029
4670ebf1c180 [gaim-migrate @ 9805]
Tim Ringenbach <marv@pidgin.im>
parents: 9028
diff changeset
3337 if (!sml)
4670ebf1c180 [gaim-migrate @ 9805]
Tim Ringenbach <marv@pidgin.im>
parents: 9028
diff changeset
3338 sml = imhtml->protocol_name;
4670ebf1c180 [gaim-migrate @ 9805]
Tim Ringenbach <marv@pidgin.im>
parents: 9028
diff changeset
3339
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
3340 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8505
780845b42f5c [gaim-migrate @ 9241]
Kevin Stange <kstange@pidgin.im>
parents: 8498
diff changeset
3341 wpos = g_snprintf (ws, smilelen + 1, "%s", c);
8473
8acf91aaffac [gaim-migrate @ 9206]
Kevin Stange <kstange@pidgin.im>
parents: 8466
diff changeset
3342
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
3343 gtk_imhtml_insert_smiley_at_iter(imhtml, sml, ws, iter);
8473
8acf91aaffac [gaim-migrate @ 9206]
Kevin Stange <kstange@pidgin.im>
parents: 8466
diff changeset
3344
8505
780845b42f5c [gaim-migrate @ 9241]
Kevin Stange <kstange@pidgin.im>
parents: 8498
diff changeset
3345 c += smilelen;
780845b42f5c [gaim-migrate @ 9241]
Kevin Stange <kstange@pidgin.im>
parents: 8498
diff changeset
3346 pos += smilelen;
8473
8acf91aaffac [gaim-migrate @ 9206]
Kevin Stange <kstange@pidgin.im>
parents: 8466
diff changeset
3347 wpos = 0;
8acf91aaffac [gaim-migrate @ 9206]
Kevin Stange <kstange@pidgin.im>
parents: 8466
diff changeset
3348 ws[0] = 0;
16144
4e022531d1c9 Patch cleanups:
Richard Laager <rlaager@pidgin.im>
parents: 16143
diff changeset
3349 } else if (*c == '&' && (amp = purple_markup_unescape_entity(c, &tlen))) {
21574
b27c242d1288 Fix #3930 by correctly detecting when we're no longer immediately following a br.
Daniel Atallah <datallah@pidgin.im>
parents: 21425
diff changeset
3350 br = FALSE;
7280
f00e23f50698 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
3351 while(*amp) {
f00e23f50698 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
3352 ws [wpos++] = *amp++;
f00e23f50698 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
3353 }
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
3354 c += tlen;
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
3355 pos += tlen;
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
3356 } else if (*c == '\n') {
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
3357 if (!(options & GTK_IMHTML_NO_NEWLINE)) {
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
3358 ws[wpos] = '\n';
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
3359 wpos++;
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
3360 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
25007
ef8bc1f4a6ba Pass only the URL scheme to gtkimhtml and let it add the colon automatically.
Richard Laager <rlaager@pidgin.im>
parents: 24698
diff changeset
3361 ws[0] = '\0'; wpos = 0;
8177
33b3a01c6318 [gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents: 8149
diff changeset
3362 /* NEW_BIT (NEW_TEXT_BIT); */
10217
0ba0263c657f [gaim-migrate @ 11345]
Daniel Westermann-Clark
parents: 10184
diff changeset
3363 } else if (!br) { /* Don't insert a space immediately after an HTML break */
9621
9c25e270b20b [gaim-migrate @ 10465]
Sean Egan <seanegan@pidgin.im>
parents: 9612
diff changeset
3364 /* A newline is defined by HTML as whitespace, which means we have to replace it with a word boundary.
9c25e270b20b [gaim-migrate @ 10465]
Sean Egan <seanegan@pidgin.im>
parents: 9612
diff changeset
3365 * word breaks vary depending on the language used, so the correct thing to do is to use Pango to determine
9c25e270b20b [gaim-migrate @ 10465]
Sean Egan <seanegan@pidgin.im>
parents: 9612
diff changeset
3366 * what language this is, determine the proper word boundary to use, and insert that. I'm just going to insert
9c25e270b20b [gaim-migrate @ 10465]
Sean Egan <seanegan@pidgin.im>
parents: 9612
diff changeset
3367 * a space instead. What are the non-English speakers going to do? Complain in a language I'll understand?
9c25e270b20b [gaim-migrate @ 10465]
Sean Egan <seanegan@pidgin.im>
parents: 9612
diff changeset
3368 * Bu-wahaha! */
9c25e270b20b [gaim-migrate @ 10465]
Sean Egan <seanegan@pidgin.im>
parents: 9612
diff changeset
3369 ws[wpos] = ' ';
9c25e270b20b [gaim-migrate @ 10465]
Sean Egan <seanegan@pidgin.im>
parents: 9612
diff changeset
3370 wpos++;
9c25e270b20b [gaim-migrate @ 10465]
Sean Egan <seanegan@pidgin.im>
parents: 9612
diff changeset
3371 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
25007
ef8bc1f4a6ba Pass only the URL scheme to gtkimhtml and let it add the colon automatically.
Richard Laager <rlaager@pidgin.im>
parents: 24698
diff changeset
3372 ws[0] = '\0'; wpos = 0;
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
3373 }
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
3374 c++;
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
3375 pos++;
25011
39bfe35b2980 Only find URLs on word boundaries to fix a bug rlaager noticed.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25008
diff changeset
3376 } else if ((pos == 0 || wpos == 0 || isspace(*(c - 1))) &&
25908
c863fcecb7dd Do not linkify unless <proto> is followed by some non-whitespace string.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25906
diff changeset
3377 (len_protocol = gtk_imhtml_is_protocol(c)) > 0 &&
26655
95790807b4d7 Fix the auto-linking of protocols.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25908
diff changeset
3378 c[len_protocol] && !isspace(c[len_protocol]) &&
95790807b4d7 Fix the auto-linking of protocols.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25908
diff changeset
3379 (c[len_protocol] != '<' || !gtk_imhtml_is_tag(c + 1, NULL, NULL, NULL))) {
21574
b27c242d1288 Fix #3930 by correctly detecting when we're no longer immediately following a br.
Daniel Atallah <datallah@pidgin.im>
parents: 21425
diff changeset
3380 br = FALSE;
24674
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
3381 if (wpos > 0) {
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
3382 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
25007
ef8bc1f4a6ba Pass only the URL scheme to gtkimhtml and let it add the colon automatically.
Richard Laager <rlaager@pidgin.im>
parents: 24698
diff changeset
3383 ws[0] = '\0'; wpos = 0;
24674
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
3384 }
25007
ef8bc1f4a6ba Pass only the URL scheme to gtkimhtml and let it add the colon automatically.
Richard Laager <rlaager@pidgin.im>
parents: 24698
diff changeset
3385 while (len_protocol--) {
ef8bc1f4a6ba Pass only the URL scheme to gtkimhtml and let it add the colon automatically.
Richard Laager <rlaager@pidgin.im>
parents: 24698
diff changeset
3386 /* Skip the next len_protocol characters, but
ef8bc1f4a6ba Pass only the URL scheme to gtkimhtml and let it add the colon automatically.
Richard Laager <rlaager@pidgin.im>
parents: 24698
diff changeset
3387 * make sure they're copied into the ws array.
ef8bc1f4a6ba Pass only the URL scheme to gtkimhtml and let it add the colon automatically.
Richard Laager <rlaager@pidgin.im>
parents: 24698
diff changeset
3388 */
ef8bc1f4a6ba Pass only the URL scheme to gtkimhtml and let it add the colon automatically.
Richard Laager <rlaager@pidgin.im>
parents: 24698
diff changeset
3389 ws [wpos++] = *c++;
ef8bc1f4a6ba Pass only the URL scheme to gtkimhtml and let it add the colon automatically.
Richard Laager <rlaager@pidgin.im>
parents: 24698
diff changeset
3390 pos++;
8334
63e80b767766 [gaim-migrate @ 9058]
Nathan Owens
parents: 8317
diff changeset
3391 }
25017
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
3392 if (!imhtml->edit.link && (imhtml->format_functions & GTK_IMHTML_LINK)) {
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
3393 while (*c && !isspace((int)*c) &&
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
3394 (*c != '<' || !gtk_imhtml_is_tag(c + 1, NULL, NULL, NULL))) {
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
3395 if (*c == '&' && (amp = purple_markup_unescape_entity(c, &tlen))) {
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
3396 while (*amp)
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
3397 ws[wpos++] = *amp++;
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
3398 c += tlen;
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
3399 pos += tlen;
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
3400 } else {
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
3401 ws [wpos++] = *c++;
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
3402 pos++;
139df1ee9854 Fix the linkification error where bad things happened if you copy/pasted
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25014
diff changeset
3403 }
24674
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
3404 }
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
3405 ws[wpos] = '\0';
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
3406 gtk_imhtml_toggle_link(imhtml, ws);
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
3407 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
3408 ws[0] = '\0'; wpos = 0;
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
3409 gtk_imhtml_toggle_link(imhtml, NULL);
8334
63e80b767766 [gaim-migrate @ 9058]
Nathan Owens
parents: 8317
diff changeset
3410 }
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3411 } else if (*c) {
21574
b27c242d1288 Fix #3930 by correctly detecting when we're no longer immediately following a br.
Daniel Atallah <datallah@pidgin.im>
parents: 21425
diff changeset
3412 br = FALSE;
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
3413 ws [wpos++] = *c++;
2856
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
3414 pos++;
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
3415 } else {
046ed5e89321 [gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2826
diff changeset
3416 break;
1428
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
3417 }
c14bab2b74bb [gaim-migrate @ 1438]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
diff changeset
3418 }
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
3419 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3420 ws[0] = '\0'; wpos = 0;
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3421
8177
33b3a01c6318 [gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents: 8149
diff changeset
3422 /* NEW_BIT(NEW_TEXT_BIT); */
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3423
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3424 if(align_right) {
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3425 /* insert RLM+LRM at beginning of the line to set alignment */
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3426 GtkTextIter line_iter;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3427 line_iter = *iter;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3428 gtk_text_iter_set_line(&line_iter, align_line);
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3429 /* insert RLM character to set alignment */
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3430 ws[wpos++] = 0xE2;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3431 ws[wpos++] = 0x80;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3432 ws[wpos++] = 0x8F;
25888
d0fdd378a635 Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents: 25854
diff changeset
3433
16144
4e022531d1c9 Patch cleanups:
Richard Laager <rlaager@pidgin.im>
parents: 16143
diff changeset
3434 if (!rtl_direction)
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3435 {
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3436 /* insert LRM character to set direction */
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3437 /* (alignment=right and direction=LTR) */
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3438 ws[wpos++] = 0xE2;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3439 ws[wpos++] = 0x80;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3440 ws[wpos++] = 0x8E;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3441 }
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3442
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3443 ws[wpos] = '\0';
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3444 gtk_text_buffer_insert(imhtml->text_buffer, &line_iter, ws, wpos);
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3445 gtk_text_buffer_get_end_iter(gtk_text_iter_get_buffer(&line_iter), iter);
25007
ef8bc1f4a6ba Pass only the URL scheme to gtkimhtml and let it add the colon automatically.
Richard Laager <rlaager@pidgin.im>
parents: 24698
diff changeset
3446 ws[0] = '\0'; wpos = 0;
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3447 }
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
3448
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
3449 while (fonts) {
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3450 GtkIMHtmlFontDetail *font = fonts->data;
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
3451 fonts = g_slist_remove (fonts, font);
14097
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 14010
diff changeset
3452 g_free (font->face);
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 14010
diff changeset
3453 g_free (font->fore);
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 14010
diff changeset
3454 g_free (font->back);
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 14010
diff changeset
3455 g_free (font->sml);
4032
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
3456 g_free (font);
e93f7af4a610 [gaim-migrate @ 4238]
Sean Egan <seanegan@pidgin.im>
parents: 3941
diff changeset
3457 }
8932
4b122cbfa7df [gaim-migrate @ 9702]
Tim Ringenbach <marv@pidgin.im>
parents: 8931
diff changeset
3458
4b122cbfa7df [gaim-migrate @ 9702]
Tim Ringenbach <marv@pidgin.im>
parents: 8931
diff changeset
3459 g_free(ws);
13138
4d3bd039da3e [gaim-migrate @ 15499]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13137
diff changeset
3460 g_free(bg);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
3461
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
3462 if (!imhtml->wbfo)
8698
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
3463 gtk_imhtml_close_tags(imhtml, iter);
8506
76ce3a78b130 [gaim-migrate @ 9242]
Gary Kramlich <grim@pidgin.im>
parents: 8505
diff changeset
3464
15403
116f7fcb07a8 [gaim-migrate @ 18134]
Sean Egan <seanegan@pidgin.im>
parents: 15391
diff changeset
3465 object = g_object_ref(G_OBJECT(imhtml));
8506
76ce3a78b130 [gaim-migrate @ 9242]
Gary Kramlich <grim@pidgin.im>
parents: 8505
diff changeset
3466 g_signal_emit(object, signals[UPDATE_FORMAT], 0);
76ce3a78b130 [gaim-migrate @ 9242]
Gary Kramlich <grim@pidgin.im>
parents: 8505
diff changeset
3467 g_object_unref(object);
15420
2dfadb432902 [gaim-migrate @ 18151]
Sean Egan <seanegan@pidgin.im>
parents: 15411
diff changeset
3468
22834
1394e7efb818 Smiley insertions can be undone with this fix. References #5577. But redo
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22810
diff changeset
3469 gtk_text_buffer_end_user_action(imhtml->text_buffer);
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
3470 }
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
3471
4892
37b4a5ac5ebe [gaim-migrate @ 5222]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
3472 void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml)
37b4a5ac5ebe [gaim-migrate @ 5222]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
3473 {
4288
a93533dc8be2 [gaim-migrate @ 4541]
Sean Egan <seanegan@pidgin.im>
parents: 4264
diff changeset
3474 g_hash_table_destroy(imhtml->smiley_data);
a93533dc8be2 [gaim-migrate @ 4541]
Sean Egan <seanegan@pidgin.im>
parents: 4264
diff changeset
3475 gtk_smiley_tree_destroy(imhtml->default_smilies);
4892
37b4a5ac5ebe [gaim-migrate @ 5222]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
3476 imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal,
4902
e7cb2fed937e [gaim-migrate @ 5236]
Nathan Walp <nwalp@pidgin.im>
parents: 4895
diff changeset
3477 g_free, (GDestroyNotify)gtk_smiley_tree_destroy);
4288
a93533dc8be2 [gaim-migrate @ 4541]
Sean Egan <seanegan@pidgin.im>
parents: 4264
diff changeset
3478 imhtml->default_smilies = gtk_smiley_tree_new();
a93533dc8be2 [gaim-migrate @ 4541]
Sean Egan <seanegan@pidgin.im>
parents: 4264
diff changeset
3479 }
8481
7a9eb76e8eee [gaim-migrate @ 9214]
Gary Kramlich <grim@pidgin.im>
parents: 8473
diff changeset
3480
3922
61808e62e68e [gaim-migrate @ 4094]
Sean Egan <seanegan@pidgin.im>
parents: 3717
diff changeset
3481 void gtk_imhtml_show_comments (GtkIMHtml *imhtml,
4253
a1fa2170cb2d [gaim-migrate @ 4504]
Sean Egan <seanegan@pidgin.im>
parents: 4201
diff changeset
3482 gboolean show)
a1fa2170cb2d [gaim-migrate @ 4504]
Sean Egan <seanegan@pidgin.im>
parents: 4201
diff changeset
3483 {
22486
e77232ab761f Disable invisible text things, if someone can conclusively prove this is
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 22276
diff changeset
3484 #if FALSE && GTK_CHECK_VERSION(2,10,10)
22211
7f3cecdb079c disapproval of revision '2c96f5a301400781ce5fbf144ffdbae44f895281'
Sean Egan <seanegan@pidgin.im>
parents: 22210
diff changeset
3485 GtkTextTag *tag;
7f3cecdb079c disapproval of revision '2c96f5a301400781ce5fbf144ffdbae44f895281'
Sean Egan <seanegan@pidgin.im>
parents: 22210
diff changeset
3486 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), "comment");
7f3cecdb079c disapproval of revision '2c96f5a301400781ce5fbf144ffdbae44f895281'
Sean Egan <seanegan@pidgin.im>
parents: 22210
diff changeset
3487 if (tag)
7f3cecdb079c disapproval of revision '2c96f5a301400781ce5fbf144ffdbae44f895281'
Sean Egan <seanegan@pidgin.im>
parents: 22210
diff changeset
3488 g_object_set(G_OBJECT(tag), "invisible", !show, NULL);
7f3cecdb079c disapproval of revision '2c96f5a301400781ce5fbf144ffdbae44f895281'
Sean Egan <seanegan@pidgin.im>
parents: 22210
diff changeset
3489 #endif
6124
322206d79652 [gaim-migrate @ 6598]
Mark Doliner <markdoliner@pidgin.im>
parents: 6066
diff changeset
3490 imhtml->show_comments = show;
4253
a1fa2170cb2d [gaim-migrate @ 4504]
Sean Egan <seanegan@pidgin.im>
parents: 4201
diff changeset
3491 }
1780
431333222954 [gaim-migrate @ 1790]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 1738
diff changeset
3492
11814
5003711283c0 [gaim-migrate @ 14105]
Richard Laager <rlaager@pidgin.im>
parents: 11768
diff changeset
3493 const char *
5003711283c0 [gaim-migrate @ 14105]
Richard Laager <rlaager@pidgin.im>
parents: 11768
diff changeset
3494 gtk_imhtml_get_protocol_name(GtkIMHtml *imhtml) {
5003711283c0 [gaim-migrate @ 14105]
Richard Laager <rlaager@pidgin.im>
parents: 11768
diff changeset
3495 return imhtml->protocol_name;
5003711283c0 [gaim-migrate @ 14105]
Richard Laager <rlaager@pidgin.im>
parents: 11768
diff changeset
3496 }
5003711283c0 [gaim-migrate @ 14105]
Richard Laager <rlaager@pidgin.im>
parents: 11768
diff changeset
3497
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
3498 void
9029
4670ebf1c180 [gaim-migrate @ 9805]
Tim Ringenbach <marv@pidgin.im>
parents: 9028
diff changeset
3499 gtk_imhtml_set_protocol_name(GtkIMHtml *imhtml, const gchar *protocol_name) {
14097
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 14010
diff changeset
3500 g_free(imhtml->protocol_name);
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 14010
diff changeset
3501 imhtml->protocol_name = g_strdup(protocol_name);
8456
63fcac86a8fd [gaim-migrate @ 9186]
Gary Kramlich <grim@pidgin.im>
parents: 8439
diff changeset
3502 }
63fcac86a8fd [gaim-migrate @ 9186]
Gary Kramlich <grim@pidgin.im>
parents: 8439
diff changeset
3503
1780
431333222954 [gaim-migrate @ 1790]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 1738
diff changeset
3504 void
11224
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3505 gtk_imhtml_delete(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) {
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3506 GList *l;
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3507 GSList *sl;
11234
e23fd86e7581 [gaim-migrate @ 13377]
Daniel Atallah <datallah@pidgin.im>
parents: 11233
diff changeset
3508 GtkTextIter i, i_s, i_e;
8427
b99f5085af0a [gaim-migrate @ 9157]
Sean Egan <seanegan@pidgin.im>
parents: 8420
diff changeset
3509 GObject *object = g_object_ref(G_OBJECT(imhtml));
11224
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3510
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3511 if (start == NULL) {
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3512 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &i_s);
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3513 start = &i_s;
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3514 }
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3515
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3516 if (end == NULL) {
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3517 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &i_e);
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3518 end = &i_e;
7991
845539e84417 [gaim-migrate @ 8668]
Ka-Hing Cheung <khc@pidgin.im>
parents: 7988
diff changeset
3519 }
11224
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3520
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3521 l = imhtml->scalables;
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3522 while (l) {
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3523 GList *next = l->next;
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3524 struct scalable_data *sd = l->data;
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3525 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer,
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3526 &i, sd->mark);
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3527 if (gtk_text_iter_in_range(&i, start, end)) {
21063
911e85f207c7 Fix some leaks caused by misuse of g_list_remove_link() instead of g_list_delete_link().
Daniel Atallah <datallah@pidgin.im>
parents: 20638
diff changeset
3528 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(sd->scalable);
11224
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3529 scale->free(scale);
21063
911e85f207c7 Fix some leaks caused by misuse of g_list_remove_link() instead of g_list_delete_link().
Daniel Atallah <datallah@pidgin.im>
parents: 20638
diff changeset
3530 g_free(sd);
911e85f207c7 Fix some leaks caused by misuse of g_list_remove_link() instead of g_list_delete_link().
Daniel Atallah <datallah@pidgin.im>
parents: 20638
diff changeset
3531 imhtml->scalables = g_list_delete_link(imhtml->scalables, l);
11224
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3532 }
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3533 l = next;
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3534 }
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3535
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3536 sl = imhtml->im_images;
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3537 while (sl) {
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3538 GSList *next = sl->next;
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3539 struct im_image_data *img_data = sl->data;
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3540 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer,
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3541 &i, img_data->mark);
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3542 if (gtk_text_iter_in_range(&i, start, end)) {
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3543 if (imhtml->funcs->image_unref)
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3544 imhtml->funcs->image_unref(img_data->id);
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3545 imhtml->im_images = g_slist_delete_link(imhtml->im_images, sl);
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3546 g_free(img_data);
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3547 }
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3548 sl = next;
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3549 }
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
3550 gtk_text_buffer_delete(imhtml->text_buffer, start, end);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3551
29378
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
3552 g_object_set_data(G_OBJECT(imhtml), "gtkimhtml_numsmileys_total", GINT_TO_POINTER(0));
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
3553
8427
b99f5085af0a [gaim-migrate @ 9157]
Sean Egan <seanegan@pidgin.im>
parents: 8420
diff changeset
3554 g_object_unref(object);
1780
431333222954 [gaim-migrate @ 1790]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 1738
diff changeset
3555 }
2363
0767c14d7879 [gaim-migrate @ 2376]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents: 2349
diff changeset
3556
4046
3b7f7799fe5b [gaim-migrate @ 4254]
Sean Egan <seanegan@pidgin.im>
parents: 4041
diff changeset
3557 void gtk_imhtml_page_up (GtkIMHtml *imhtml)
3b7f7799fe5b [gaim-migrate @ 4254]
Sean Egan <seanegan@pidgin.im>
parents: 4041
diff changeset
3558 {
5282
bd9ed6f2175c [gaim-migrate @ 5654]
Ka-Hing Cheung <khc@pidgin.im>
parents: 5177
diff changeset
3559 GdkRectangle rect;
bd9ed6f2175c [gaim-migrate @ 5654]
Ka-Hing Cheung <khc@pidgin.im>
parents: 5177
diff changeset
3560 GtkTextIter iter;
4046
3b7f7799fe5b [gaim-migrate @ 4254]
Sean Egan <seanegan@pidgin.im>
parents: 4041
diff changeset
3561
5282
bd9ed6f2175c [gaim-migrate @ 5654]
Ka-Hing Cheung <khc@pidgin.im>
parents: 5177
diff changeset
3562 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect);
bd9ed6f2175c [gaim-migrate @ 5654]
Ka-Hing Cheung <khc@pidgin.im>
parents: 5177
diff changeset
3563 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x,
bd9ed6f2175c [gaim-migrate @ 5654]
Ka-Hing Cheung <khc@pidgin.im>
parents: 5177
diff changeset
3564 rect.y - rect.height);
bd9ed6f2175c [gaim-migrate @ 5654]
Ka-Hing Cheung <khc@pidgin.im>
parents: 5177
diff changeset
3565 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
3566
4046
3b7f7799fe5b [gaim-migrate @ 4254]
Sean Egan <seanegan@pidgin.im>
parents: 4041
diff changeset
3567 }
5282
bd9ed6f2175c [gaim-migrate @ 5654]
Ka-Hing Cheung <khc@pidgin.im>
parents: 5177
diff changeset
3568 void gtk_imhtml_page_down (GtkIMHtml *imhtml)
bd9ed6f2175c [gaim-migrate @ 5654]
Ka-Hing Cheung <khc@pidgin.im>
parents: 5177
diff changeset
3569 {
bd9ed6f2175c [gaim-migrate @ 5654]
Ka-Hing Cheung <khc@pidgin.im>
parents: 5177
diff changeset
3570 GdkRectangle rect;
bd9ed6f2175c [gaim-migrate @ 5654]
Ka-Hing Cheung <khc@pidgin.im>
parents: 5177
diff changeset
3571 GtkTextIter iter;
bd9ed6f2175c [gaim-migrate @ 5654]
Ka-Hing Cheung <khc@pidgin.im>
parents: 5177
diff changeset
3572
bd9ed6f2175c [gaim-migrate @ 5654]
Ka-Hing Cheung <khc@pidgin.im>
parents: 5177
diff changeset
3573 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect);
bd9ed6f2175c [gaim-migrate @ 5654]
Ka-Hing Cheung <khc@pidgin.im>
parents: 5177
diff changeset
3574 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x,
bd9ed6f2175c [gaim-migrate @ 5654]
Ka-Hing Cheung <khc@pidgin.im>
parents: 5177
diff changeset
3575 rect.y + rect.height);
bd9ed6f2175c [gaim-migrate @ 5654]
Ka-Hing Cheung <khc@pidgin.im>
parents: 5177
diff changeset
3576 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0);
bd9ed6f2175c [gaim-migrate @ 5654]
Ka-Hing Cheung <khc@pidgin.im>
parents: 5177
diff changeset
3577 }
4735
ac5f2489f6ee [gaim-migrate @ 5050]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4635
diff changeset
3578
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3579 /* GtkIMHtmlScalable, gtk_imhtml_image, gtk_imhtml_hr */
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
3580 GtkIMHtmlScalable *gtk_imhtml_image_new(GdkPixbuf *img, const gchar *filename, int id)
4735
ac5f2489f6ee [gaim-migrate @ 5050]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4635
diff changeset
3581 {
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3582 GtkIMHtmlImage *im_image = g_malloc(sizeof(GtkIMHtmlImage));
4895
51794f61995e [gaim-migrate @ 5227]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4892
diff changeset
3583
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3584 GTK_IMHTML_SCALABLE(im_image)->scale = gtk_imhtml_image_scale;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3585 GTK_IMHTML_SCALABLE(im_image)->add_to = gtk_imhtml_image_add_to;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3586 GTK_IMHTML_SCALABLE(im_image)->free = gtk_imhtml_image_free;
5046
ba5af38017fa [gaim-migrate @ 5394]
Ka-Hing Cheung <khc@pidgin.im>
parents: 5020
diff changeset
3587
ba5af38017fa [gaim-migrate @ 5394]
Ka-Hing Cheung <khc@pidgin.im>
parents: 5020
diff changeset
3588 im_image->pixbuf = img;
18151
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3589 im_image->image = GTK_IMAGE(gtk_image_new_from_pixbuf(im_image->pixbuf));
4895
51794f61995e [gaim-migrate @ 5227]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4892
diff changeset
3590 im_image->width = gdk_pixbuf_get_width(img);
51794f61995e [gaim-migrate @ 5227]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4892
diff changeset
3591 im_image->height = gdk_pixbuf_get_height(img);
51794f61995e [gaim-migrate @ 5227]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4892
diff changeset
3592 im_image->mark = NULL;
14097
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 14010
diff changeset
3593 im_image->filename = g_strdup(filename);
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
3594 im_image->id = id;
9573
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3595 im_image->filesel = NULL;
4895
51794f61995e [gaim-migrate @ 5227]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4892
diff changeset
3596
5046
ba5af38017fa [gaim-migrate @ 5394]
Ka-Hing Cheung <khc@pidgin.im>
parents: 5020
diff changeset
3597 g_object_ref(img);
4895
51794f61995e [gaim-migrate @ 5227]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4892
diff changeset
3598 return GTK_IMHTML_SCALABLE(im_image);
51794f61995e [gaim-migrate @ 5227]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4892
diff changeset
3599 }
51794f61995e [gaim-migrate @ 5227]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4892
diff changeset
3600
18151
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3601 static gboolean
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3602 animate_image_cb(gpointer data)
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3603 {
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3604 GtkIMHtmlImage *im_image;
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3605 int width, height;
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3606 int delay;
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3607
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3608 im_image = data;
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3609
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3610 /* Update the pointer to this GdkPixbuf frame of the animation */
20638
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
3611 if (gdk_pixbuf_animation_iter_advance(GTK_IMHTML_ANIMATION(im_image)->iter, NULL)) {
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
3612 GdkPixbuf *pb = gdk_pixbuf_animation_iter_get_pixbuf(GTK_IMHTML_ANIMATION(im_image)->iter);
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
3613 g_object_unref(G_OBJECT(im_image->pixbuf));
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
3614 im_image->pixbuf = gdk_pixbuf_copy(pb);
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
3615
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
3616 /* Update the displayed GtkImage */
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
3617 width = gdk_pixbuf_get_width(gtk_image_get_pixbuf(im_image->image));
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
3618 height = gdk_pixbuf_get_height(gtk_image_get_pixbuf(im_image->image));
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
3619 if (width > 0 && height > 0)
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
3620 {
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
3621 /* Need to scale the new frame to the same size as the old frame */
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
3622 GdkPixbuf *tmp;
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
3623 tmp = gdk_pixbuf_scale_simple(im_image->pixbuf, width, height, GDK_INTERP_BILINEAR);
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
3624 gtk_image_set_from_pixbuf(im_image->image, tmp);
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
3625 g_object_unref(G_OBJECT(tmp));
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
3626 } else {
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
3627 /* Display at full-size */
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
3628 gtk_image_set_from_pixbuf(im_image->image, im_image->pixbuf);
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
3629 }
18151
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3630 }
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3631
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3632 delay = MIN(gdk_pixbuf_animation_iter_get_delay_time(GTK_IMHTML_ANIMATION(im_image)->iter), 100);
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3633 GTK_IMHTML_ANIMATION(im_image)->timer = g_timeout_add(delay, animate_image_cb, im_image);
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3634
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3635 return FALSE;
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3636 }
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3637
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3638 GtkIMHtmlScalable *gtk_imhtml_animation_new(GdkPixbufAnimation *anim, const gchar *filename, int id)
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3639 {
22703
2cc5d0981559 Fix animated icons that have been right-clicked causing crashes when the imhtml is destroyed. Fixes #5217.
Daniel Atallah <datallah@pidgin.im>
parents: 22596
diff changeset
3640 GtkIMHtmlImage *im_image = (GtkIMHtmlImage *) g_new0(GtkIMHtmlAnimation, 1);
18151
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3641
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3642 GTK_IMHTML_SCALABLE(im_image)->scale = gtk_imhtml_image_scale;
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3643 GTK_IMHTML_SCALABLE(im_image)->add_to = gtk_imhtml_image_add_to;
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3644 GTK_IMHTML_SCALABLE(im_image)->free = gtk_imhtml_animation_free;
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3645
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3646 GTK_IMHTML_ANIMATION(im_image)->anim = anim;
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3647 if (gdk_pixbuf_animation_is_static_image(anim)) {
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3648 im_image->pixbuf = gdk_pixbuf_animation_get_static_image(anim);
20638
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
3649 g_object_ref(im_image->pixbuf);
18151
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3650 } else {
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3651 int delay;
20638
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
3652 GdkPixbuf *pb;
18151
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3653 GTK_IMHTML_ANIMATION(im_image)->iter = gdk_pixbuf_animation_get_iter(anim, NULL);
20638
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
3654 pb = gdk_pixbuf_animation_iter_get_pixbuf(GTK_IMHTML_ANIMATION(im_image)->iter);
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
3655 im_image->pixbuf = gdk_pixbuf_copy(pb);
18151
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3656 delay = MIN(gdk_pixbuf_animation_iter_get_delay_time(GTK_IMHTML_ANIMATION(im_image)->iter), 100);
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3657 GTK_IMHTML_ANIMATION(im_image)->timer = g_timeout_add(delay, animate_image_cb, im_image);
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3658 }
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3659 im_image->image = GTK_IMAGE(gtk_image_new_from_pixbuf(im_image->pixbuf));
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3660 im_image->width = gdk_pixbuf_animation_get_width(anim);
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3661 im_image->height = gdk_pixbuf_animation_get_height(anim);
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3662 im_image->filename = g_strdup(filename);
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3663 im_image->id = id;
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3664
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3665 g_object_ref(anim);
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3666
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3667 return GTK_IMHTML_SCALABLE(im_image);
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3668 }
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3669
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3670 void gtk_imhtml_image_scale(GtkIMHtmlScalable *scale, int width, int height)
4895
51794f61995e [gaim-migrate @ 5227]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4892
diff changeset
3671 {
11867
de448bc5da1a [gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 11844
diff changeset
3672 GtkIMHtmlImage *im_image = (GtkIMHtmlImage *)scale;
de448bc5da1a [gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 11844
diff changeset
3673
de448bc5da1a [gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 11844
diff changeset
3674 if (im_image->width > width || im_image->height > height) {
11840
c9ec5a42d420 [gaim-migrate @ 14131]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 11820
diff changeset
3675 double ratio_w, ratio_h, ratio;
c9ec5a42d420 [gaim-migrate @ 14131]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 11820
diff changeset
3676 int new_h, new_w;
4895
51794f61995e [gaim-migrate @ 5227]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4892
diff changeset
3677 GdkPixbuf *new_image = NULL;
11840
c9ec5a42d420 [gaim-migrate @ 14131]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 11820
diff changeset
3678
11867
de448bc5da1a [gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 11844
diff changeset
3679 ratio_w = ((double)width - 2) / im_image->width;
de448bc5da1a [gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 11844
diff changeset
3680 ratio_h = ((double)height - 2) / im_image->height;
11840
c9ec5a42d420 [gaim-migrate @ 14131]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 11820
diff changeset
3681
c9ec5a42d420 [gaim-migrate @ 14131]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 11820
diff changeset
3682 ratio = (ratio_w < ratio_h) ? ratio_w : ratio_h;
c9ec5a42d420 [gaim-migrate @ 14131]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 11820
diff changeset
3683
11867
de448bc5da1a [gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 11844
diff changeset
3684 new_w = (int)(im_image->width * ratio);
de448bc5da1a [gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 11844
diff changeset
3685 new_h = (int)(im_image->height * ratio);
de448bc5da1a [gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 11844
diff changeset
3686
de448bc5da1a [gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 11844
diff changeset
3687 new_image = gdk_pixbuf_scale_simple(im_image->pixbuf, new_w, new_h, GDK_INTERP_BILINEAR);
de448bc5da1a [gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 11844
diff changeset
3688 gtk_image_set_from_pixbuf(im_image->image, new_image);
de448bc5da1a [gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 11844
diff changeset
3689 g_object_unref(G_OBJECT(new_image));
de448bc5da1a [gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 11844
diff changeset
3690 } else if (gdk_pixbuf_get_width(gtk_image_get_pixbuf(im_image->image)) != im_image->width) {
de448bc5da1a [gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 11844
diff changeset
3691 /* Enough space to show the full-size of the image. */
de448bc5da1a [gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 11844
diff changeset
3692 GdkPixbuf *new_image;
de448bc5da1a [gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 11844
diff changeset
3693
de448bc5da1a [gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 11844
diff changeset
3694 new_image = gdk_pixbuf_scale_simple(im_image->pixbuf, im_image->width, im_image->height, GDK_INTERP_BILINEAR);
de448bc5da1a [gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 11844
diff changeset
3695 gtk_image_set_from_pixbuf(im_image->image, new_image);
4895
51794f61995e [gaim-migrate @ 5227]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4892
diff changeset
3696 g_object_unref(G_OBJECT(new_image));
51794f61995e [gaim-migrate @ 5227]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4892
diff changeset
3697 }
51794f61995e [gaim-migrate @ 5227]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4892
diff changeset
3698 }
51794f61995e [gaim-migrate @ 5227]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4892
diff changeset
3699
9573
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3700 static void
27123
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3701 image_save_yes_cb(GtkIMHtmlImageSave *save, const char *filename)
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3702 {
5019
ac3e5e1f588a [gaim-migrate @ 5355]
Luke Schierer <lschiere@pidgin.im>
parents: 5015
diff changeset
3703 GError *error = NULL;
27123
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3704 GtkIMHtmlImage *image = (GtkIMHtmlImage *)save->image;
5012
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3705
9573
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3706 gtk_widget_destroy(image->filesel);
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3707 image->filesel = NULL;
5959
827dbe4b5bb2 [gaim-migrate @ 6405]
Mark Doliner <markdoliner@pidgin.im>
parents: 5582
diff changeset
3708
27123
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3709 if (save->data && save->datasize) {
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3710 g_file_set_contents(filename, save->data, save->datasize, &error);
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3711 } else {
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3712 gchar *type = NULL;
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3713 GSList *formats = gdk_pixbuf_get_formats();
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3714 char *newfilename;
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3715
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3716 while (formats) {
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3717 GdkPixbufFormat *format = formats->data;
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3718 gchar **extensions = gdk_pixbuf_format_get_extensions(format);
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3719 gpointer p = extensions;
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3720
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3721 while(gdk_pixbuf_format_is_writable(format) && extensions && extensions[0]){
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3722 gchar *fmt_ext = extensions[0];
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3723 const gchar* file_ext = filename + strlen(filename) - strlen(fmt_ext);
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3724
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3725 if(!g_ascii_strcasecmp(fmt_ext, file_ext)){
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3726 type = gdk_pixbuf_format_get_name(format);
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3727 break;
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3728 }
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3729
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3730 extensions++;
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3731 }
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3732
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3733 g_strfreev(p);
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3734
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3735 if (type)
5012
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3736 break;
27123
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3737
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3738 formats = formats->next;
5012
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3739 }
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3740
27123
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3741 g_slist_free(formats);
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3742
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3743 /* If I can't find a valid type, I will just tell the user about it and then assume
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3744 it's a png */
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3745 if (!type){
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3746 char *basename, *tmp;
27125
60349fcd9f2b Preserve the location when defaulting to png for saving unsupported image format.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27123
diff changeset
3747 char *dirname;
27123
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3748 GtkWidget *dialog = gtk_message_dialog_new_with_markup(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3749 _("<span size='larger' weight='bold'>Unrecognized file type</span>\n\nDefaulting to PNG."));
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3750
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3751 g_signal_connect_swapped(dialog, "response", G_CALLBACK (gtk_widget_destroy), dialog);
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3752 gtk_widget_show(dialog);
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3753
5020
2c5a2fbb55b5 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
3754 type = g_strdup("png");
27125
60349fcd9f2b Preserve the location when defaulting to png for saving unsupported image format.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27123
diff changeset
3755 dirname = g_path_get_dirname(filename);
27123
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3756 basename = g_path_get_basename(filename);
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3757 tmp = strrchr(basename, '.');
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3758 if (tmp != NULL)
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3759 tmp[0] = '\0';
27125
60349fcd9f2b Preserve the location when defaulting to png for saving unsupported image format.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27123
diff changeset
3760 newfilename = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s.png", dirname, basename);
60349fcd9f2b Preserve the location when defaulting to png for saving unsupported image format.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27123
diff changeset
3761 g_free(dirname);
27123
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3762 g_free(basename);
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3763 } else {
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3764 /*
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3765 * We're able to save the file in it's original format, so we
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3766 * can use the original file name.
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3767 */
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3768 newfilename = g_strdup(filename);
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3769 }
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3770
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3771 gdk_pixbuf_save(image->pixbuf, newfilename, type, &error, NULL);
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3772
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3773 g_free(newfilename);
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3774 g_free(type);
5020
2c5a2fbb55b5 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
3775 }
2c5a2fbb55b5 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
3776
9573
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3777 if (error){
11019
6786068b00ab [gaim-migrate @ 12890]
Richard Laager <rlaager@pidgin.im>
parents: 11006
diff changeset
3778 GtkWidget *dialog = gtk_message_dialog_new_with_markup(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
6786068b00ab [gaim-migrate @ 12890]
Richard Laager <rlaager@pidgin.im>
parents: 11006
diff changeset
3779 _("<span size='larger' weight='bold'>Error saving image</span>\n\n%s"), error->message);
6786068b00ab [gaim-migrate @ 12890]
Richard Laager <rlaager@pidgin.im>
parents: 11006
diff changeset
3780 g_signal_connect_swapped(dialog, "response", G_CALLBACK (gtk_widget_destroy), dialog);
6786068b00ab [gaim-migrate @ 12890]
Richard Laager <rlaager@pidgin.im>
parents: 11006
diff changeset
3781 gtk_widget_show(dialog);
5012
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3782 g_error_free(error);
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3783 }
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3784 }
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3785
9573
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3786 static void
27123
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3787 image_save_check_if_exists_cb(GtkWidget *widget, gint response, GtkIMHtmlImageSave *save)
9573
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3788 {
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3789 gchar *filename;
27123
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3790 GtkIMHtmlImage *image = (GtkIMHtmlImage *)save->image;
9573
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3791
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3792 if (response != GTK_RESPONSE_ACCEPT) {
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3793 gtk_widget_destroy(widget);
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3794 image->filesel = NULL;
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3795 return;
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3796 }
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3797
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3798 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget));
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3799
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3800 /*
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3801 * XXX - We should probably prompt the user to determine if they really
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3802 * want to overwrite the file or not. However, I don't feel like doing
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3803 * that, so we're just always going to overwrite if the file exists.
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3804 */
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3805 /*
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3806 if (g_file_test(filename, G_FILE_TEST_EXISTS)) {
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3807 } else
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3808 image_save_yes_cb(image, filename);
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3809 */
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3810
27123
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3811 image_save_yes_cb(save, filename);
9573
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3812
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3813 g_free(filename);
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3814 }
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3815
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3816 static void
27123
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3817 gtk_imhtml_image_save(GtkWidget *w, GtkIMHtmlImageSave *save)
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3818 {
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3819 GtkIMHtmlImage *image = (GtkIMHtmlImage *)save->image;
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3820
9573
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3821 if (image->filesel != NULL) {
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3822 gtk_window_present(GTK_WINDOW(image->filesel));
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3823 return;
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3824 }
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3825
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3826 image->filesel = gtk_file_chooser_dialog_new(_("Save Image"),
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3827 NULL,
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3828 GTK_FILE_CHOOSER_ACTION_SAVE,
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3829 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3830 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3831 NULL);
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3832 gtk_dialog_set_default_response(GTK_DIALOG(image->filesel), GTK_RESPONSE_ACCEPT);
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3833 if (image->filename != NULL)
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3834 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(image->filesel), image->filename);
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3835 g_signal_connect(G_OBJECT(GTK_FILE_CHOOSER(image->filesel)), "response",
27123
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3836 G_CALLBACK(image_save_check_if_exists_cb), save);
9573
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3837
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3838 gtk_widget_show(image->filesel);
5012
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3839 }
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3840
23304
3aba02105818 Modified patch from malu to "Add context menu alternative to add received
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23302
diff changeset
3841 static void
27259
50ab3ce89cdb Allow adding received animated custom smileys to locale custom smiley
Andrea Piccinelli <frasten@gmail.com>
parents: 27173
diff changeset
3842 gtk_imhtml_custom_smiley_save(GtkWidget *w, GtkIMHtmlImageSave *save)
50ab3ce89cdb Allow adding received animated custom smileys to locale custom smiley
Andrea Piccinelli <frasten@gmail.com>
parents: 27173
diff changeset
3843 {
50ab3ce89cdb Allow adding received animated custom smileys to locale custom smiley
Andrea Piccinelli <frasten@gmail.com>
parents: 27173
diff changeset
3844 GtkIMHtmlImage *image = (GtkIMHtmlImage *)save->image;
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
3845
23304
3aba02105818 Modified patch from malu to "Add context menu alternative to add received
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23302
diff changeset
3846 /* Create an add dialog */
3aba02105818 Modified patch from malu to "Add context menu alternative to add received
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23302
diff changeset
3847 PidginSmiley *editor = pidgin_smiley_edit(NULL, NULL);
3aba02105818 Modified patch from malu to "Add context menu alternative to add received
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23302
diff changeset
3848 pidgin_smiley_editor_set_shortcut(editor, image->filename);
3aba02105818 Modified patch from malu to "Add context menu alternative to add received
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23302
diff changeset
3849 pidgin_smiley_editor_set_image(editor, image->pixbuf);
27259
50ab3ce89cdb Allow adding received animated custom smileys to locale custom smiley
Andrea Piccinelli <frasten@gmail.com>
parents: 27173
diff changeset
3850 pidgin_smiley_editor_set_data(editor, save->data, save->datasize);
23304
3aba02105818 Modified patch from malu to "Add context menu alternative to add received
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23302
diff changeset
3851 }
3aba02105818 Modified patch from malu to "Add context menu alternative to add received
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23302
diff changeset
3852
9815
fcbbbce0e1ff [gaim-migrate @ 10686]
Mark Doliner <markdoliner@pidgin.im>
parents: 9726
diff changeset
3853 /*
fcbbbce0e1ff [gaim-migrate @ 10686]
Mark Doliner <markdoliner@pidgin.im>
parents: 9726
diff changeset
3854 * So, um, AIM Direct IM lets you send any file, not just images. You can
fcbbbce0e1ff [gaim-migrate @ 10686]
Mark Doliner <markdoliner@pidgin.im>
parents: 9726
diff changeset
3855 * just insert a sound or a file or whatever in a conversation. It's
fcbbbce0e1ff [gaim-migrate @ 10686]
Mark Doliner <markdoliner@pidgin.im>
parents: 9726
diff changeset
3856 * basically like file transfer, except there is an icon to open the file
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15865
diff changeset
3857 * embedded in the conversation. Someone should make the Purple core handle
9815
fcbbbce0e1ff [gaim-migrate @ 10686]
Mark Doliner <markdoliner@pidgin.im>
parents: 9726
diff changeset
3858 * all of that.
fcbbbce0e1ff [gaim-migrate @ 10686]
Mark Doliner <markdoliner@pidgin.im>
parents: 9726
diff changeset
3859 */
27123
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3860 static gboolean gtk_imhtml_image_clicked(GtkWidget *w, GdkEvent *event, GtkIMHtmlImageSave *save)
5012
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3861 {
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3862 GdkEventButton *event_button = (GdkEventButton *) event;
27123
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3863 GtkIMHtmlImage *image = (GtkIMHtmlImage *)save->image;
5012
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3864
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3865 if (event->type == GDK_BUTTON_RELEASE) {
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3866 if(event_button->button == 3) {
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3867 GtkWidget *img, *item, *menu;
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3868 menu = gtk_menu_new();
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3869
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3870 /* buttons and such */
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3871 img = gtk_image_new_from_stock(GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU);
27122
a926d9d18bde Avoid unnecessary strdup's.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27114
diff changeset
3872 item = gtk_image_menu_item_new_with_mnemonic(_("_Save Image..."));
5012
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3873 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img);
27123
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3874 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(gtk_imhtml_image_save), save);
5012
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3875 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3876
23304
3aba02105818 Modified patch from malu to "Add context menu alternative to add received
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23302
diff changeset
3877 /* Add menu item for adding custom smiley to local smileys */
3aba02105818 Modified patch from malu to "Add context menu alternative to add received
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23302
diff changeset
3878 /* we only add the menu if the image is of "custom smiley size"
3aba02105818 Modified patch from malu to "Add context menu alternative to add received
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23302
diff changeset
3879 <= 96x96 pixels */
3aba02105818 Modified patch from malu to "Add context menu alternative to add received
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23302
diff changeset
3880 if (image->width <= 96 && image->height <= 96) {
3aba02105818 Modified patch from malu to "Add context menu alternative to add received
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23302
diff changeset
3881 img = gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU);
27122
a926d9d18bde Avoid unnecessary strdup's.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27114
diff changeset
3882 item = gtk_image_menu_item_new_with_mnemonic(_("_Add Custom Smiley..."));
23304
3aba02105818 Modified patch from malu to "Add context menu alternative to add received
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23302
diff changeset
3883 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img);
3aba02105818 Modified patch from malu to "Add context menu alternative to add received
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23302
diff changeset
3884 g_signal_connect(G_OBJECT(item), "activate",
27259
50ab3ce89cdb Allow adding received animated custom smileys to locale custom smiley
Andrea Piccinelli <frasten@gmail.com>
parents: 27173
diff changeset
3885 G_CALLBACK(gtk_imhtml_custom_smiley_save), save);
23304
3aba02105818 Modified patch from malu to "Add context menu alternative to add received
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23302
diff changeset
3886 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
3aba02105818 Modified patch from malu to "Add context menu alternative to add received
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23302
diff changeset
3887 }
3aba02105818 Modified patch from malu to "Add context menu alternative to add received
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23302
diff changeset
3888
5012
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3889 gtk_widget_show_all(menu);
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3890 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3891 event_button->button, event_button->time);
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3892
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3893 return TRUE;
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3894 }
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3895 }
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3896 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3)
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3897 return TRUE; /* Clicking the right mouse button on a link shouldn't
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3898 be caught by the regular GtkTextView menu */
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3899 else
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3900 return FALSE; /* Let clicks go through if we didn't catch anything */
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3901
a6e5bbd44d89 [gaim-migrate @ 5348]
Ka-Hing Cheung <khc@pidgin.im>
parents: 4997
diff changeset
3902 }
17009
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
3903
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
3904 static gboolean gtk_imhtml_smiley_clicked(GtkWidget *w, GdkEvent *event, GtkIMHtmlSmiley *smiley)
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
3905 {
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
3906 GdkPixbufAnimation *anim = NULL;
27123
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3907 GtkIMHtmlImageSave *save = NULL;
17009
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
3908 gboolean ret;
23304
3aba02105818 Modified patch from malu to "Add context menu alternative to add received
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23302
diff changeset
3909
17009
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
3910 if (event->type != GDK_BUTTON_RELEASE || ((GdkEventButton*)event)->button != 3)
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
3911 return FALSE;
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
3912
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
3913 anim = gtk_smiley_get_image(smiley);
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
3914 if (!anim)
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
3915 return FALSE;
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
3916
27123
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3917 save = g_new0(GtkIMHtmlImageSave, 1);
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3918 save->image = (GtkIMHtmlScalable *)gtk_imhtml_animation_new(anim, smiley->smile, 0);
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3919 save->data = smiley->data; /* Do not need to memdup here, since the smiley is not
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3920 destroyed before this GtkIMHtmlImageSave */
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3921 save->datasize = smiley->datasize;
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3922 ret = gtk_imhtml_image_clicked(w, event, save);
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3923 g_object_set_data_full(G_OBJECT(w), "image-data", save->image, (GDestroyNotify)gtk_imhtml_animation_free);
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3924 g_object_set_data_full(G_OBJECT(w), "image-save-data", save, (GDestroyNotify)g_free);
17009
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
3925 return ret;
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
3926 }
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
3927
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3928 void gtk_imhtml_image_free(GtkIMHtmlScalable *scale)
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3929 {
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3930 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3931
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3932 g_object_unref(image->pixbuf);
14097
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 14010
diff changeset
3933 g_free(image->filename);
9573
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3934 if (image->filesel)
7fb26654aee8 [gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents: 9467
diff changeset
3935 gtk_widget_destroy(image->filesel);
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3936 g_free(scale);
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3937 }
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3938
18151
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3939 void gtk_imhtml_animation_free(GtkIMHtmlScalable *scale)
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3940 {
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3941 GtkIMHtmlAnimation *animation = (GtkIMHtmlAnimation *)scale;
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3942
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3943 if (animation->timer > 0)
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3944 g_source_remove(animation->timer);
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3945 if (animation->iter != NULL)
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3946 g_object_unref(animation->iter);
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3947 g_object_unref(animation->anim);
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3948
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3949 gtk_imhtml_image_free(scale);
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3950 }
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
3951
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3952 void gtk_imhtml_image_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter)
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3953 {
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3954 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3955 GtkWidget *box = gtk_event_box_new();
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
3956 char *tag;
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3957 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter);
27123
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3958 GtkIMHtmlImageSave *save;
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3959
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3960 gtk_container_add(GTK_CONTAINER(box), GTK_WIDGET(image->image));
9229
fba36c506c60 [gaim-migrate @ 10025]
Tim Ringenbach <marv@pidgin.im>
parents: 9186
diff changeset
3961
fba36c506c60 [gaim-migrate @ 10025]
Tim Ringenbach <marv@pidgin.im>
parents: 9186
diff changeset
3962 if(!gtk_check_version(2, 4, 0))
fba36c506c60 [gaim-migrate @ 10025]
Tim Ringenbach <marv@pidgin.im>
parents: 9186
diff changeset
3963 g_object_set(G_OBJECT(box), "visible-window", FALSE, NULL);
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3964
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3965 gtk_widget_show(GTK_WIDGET(image->image));
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3966 gtk_widget_show(box);
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3967
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
3968 tag = g_strdup_printf("<IMG ID=\"%d\">", image->id);
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
3969 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_htmltext", tag, g_free);
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
3970 g_object_set_data(G_OBJECT(anchor), "gtkimhtml_plaintext", "[Image]");
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
3971
15420
2dfadb432902 [gaim-migrate @ 18151]
Sean Egan <seanegan@pidgin.im>
parents: 15411
diff changeset
3972 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), box, anchor);
27123
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3973
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3974 save = g_new0(GtkIMHtmlImageSave, 1);
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3975 save->image = scale;
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3976 g_signal_connect(G_OBJECT(box), "event", G_CALLBACK(gtk_imhtml_image_clicked), save);
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
3977 g_object_set_data_full(G_OBJECT(box), "image-save-data", save, (GDestroyNotify)g_free);
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3978 }
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3979
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3980 GtkIMHtmlScalable *gtk_imhtml_hr_new()
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3981 {
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3982 GtkIMHtmlHr *hr = g_malloc(sizeof(GtkIMHtmlHr));
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3983
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3984 GTK_IMHTML_SCALABLE(hr)->scale = gtk_imhtml_hr_scale;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3985 GTK_IMHTML_SCALABLE(hr)->add_to = gtk_imhtml_hr_add_to;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3986 GTK_IMHTML_SCALABLE(hr)->free = gtk_imhtml_hr_free;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3987
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3988 hr->sep = gtk_hseparator_new();
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3989 gtk_widget_set_size_request(hr->sep, 5000, 2);
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3990 gtk_widget_show(hr->sep);
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3991
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3992 return GTK_IMHTML_SCALABLE(hr);
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3993 }
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3994
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3995 void gtk_imhtml_hr_scale(GtkIMHtmlScalable *scale, int width, int height)
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3996 {
8588
6bcf7ed80ed8 [gaim-migrate @ 9339]
Mark Doliner <markdoliner@pidgin.im>
parents: 8568
diff changeset
3997 gtk_widget_set_size_request(((GtkIMHtmlHr *)scale)->sep, width - 2, 2);
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3998 }
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
3999
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
4000 void gtk_imhtml_hr_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter)
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
4001 {
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
4002 GtkIMHtmlHr *hr = (GtkIMHtmlHr *)scale;
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
4003 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter);
8698
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
4004 g_object_set_data(G_OBJECT(anchor), "gtkimhtml_htmltext", "<hr>");
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
4005 g_object_set_data(G_OBJECT(anchor), "gtkimhtml_plaintext", "\n---\n");
15420
2dfadb432902 [gaim-migrate @ 18151]
Sean Egan <seanegan@pidgin.im>
parents: 15411
diff changeset
4006 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), hr->sep, anchor);
5967
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
4007 }
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
4008
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
4009 void gtk_imhtml_hr_free(GtkIMHtmlScalable *scale)
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
4010 {
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
4011 g_free(scale);
df8268ccde45 [gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents: 5966
diff changeset
4012 }
7295
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4013
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4014 gboolean gtk_imhtml_search_find(GtkIMHtml *imhtml, const gchar *text)
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4015 {
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4016 GtkTextIter iter, start, end;
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4017 gboolean new_search = TRUE;
14863
82888d51234c [gaim-migrate @ 17566]
Daniel Atallah <datallah@pidgin.im>
parents: 14821
diff changeset
4018 GtkTextMark *start_mark;
7295
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4019
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4020 g_return_val_if_fail(imhtml != NULL, FALSE);
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4021 g_return_val_if_fail(text != NULL, FALSE);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4022
14863
82888d51234c [gaim-migrate @ 17566]
Daniel Atallah <datallah@pidgin.im>
parents: 14821
diff changeset
4023 start_mark = gtk_text_buffer_get_mark(imhtml->text_buffer, "search");
82888d51234c [gaim-migrate @ 17566]
Daniel Atallah <datallah@pidgin.im>
parents: 14821
diff changeset
4024
82888d51234c [gaim-migrate @ 17566]
Daniel Atallah <datallah@pidgin.im>
parents: 14821
diff changeset
4025 if (start_mark && imhtml->search_string && !strcmp(text, imhtml->search_string))
7295
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4026 new_search = FALSE;
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4027
7295
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4028 if (new_search) {
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4029 gtk_imhtml_search_clear(imhtml);
14863
82888d51234c [gaim-migrate @ 17566]
Daniel Atallah <datallah@pidgin.im>
parents: 14821
diff changeset
4030 g_free(imhtml->search_string);
82888d51234c [gaim-migrate @ 17566]
Daniel Atallah <datallah@pidgin.im>
parents: 14821
diff changeset
4031 imhtml->search_string = g_strdup(text);
15093
5501dd769dc5 [gaim-migrate @ 17814]
Sean Egan <seanegan@pidgin.im>
parents: 14970
diff changeset
4032 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter);
7295
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4033 } else {
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4034 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter,
14863
82888d51234c [gaim-migrate @ 17566]
Daniel Atallah <datallah@pidgin.im>
parents: 14821
diff changeset
4035 start_mark);
7295
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4036 }
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4037
15093
5501dd769dc5 [gaim-migrate @ 17814]
Sean Egan <seanegan@pidgin.im>
parents: 14970
diff changeset
4038 if (gtk_source_iter_backward_search(&iter, imhtml->search_string,
14400
953baf2eba1a [gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents: 14395
diff changeset
4039 GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_CASE_INSENSITIVE,
953baf2eba1a [gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents: 14395
diff changeset
4040 &start, &end, NULL))
953baf2eba1a [gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents: 14395
diff changeset
4041 {
7295
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4042 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &start, 0, TRUE, 0, 0);
15093
5501dd769dc5 [gaim-migrate @ 17814]
Sean Egan <seanegan@pidgin.im>
parents: 14970
diff changeset
4043 gtk_text_buffer_create_mark(imhtml->text_buffer, "search", &start, FALSE);
14400
953baf2eba1a [gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents: 14395
diff changeset
4044 if (new_search)
953baf2eba1a [gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents: 14395
diff changeset
4045 {
7295
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4046 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &iter, &end);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4047 do
7295
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4048 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "search", &start, &end);
15093
5501dd769dc5 [gaim-migrate @ 17814]
Sean Egan <seanegan@pidgin.im>
parents: 14970
diff changeset
4049 while (gtk_source_iter_backward_search(&start, imhtml->search_string,
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4050 GTK_SOURCE_SEARCH_VISIBLE_ONLY |
7358
129ed09d791d [gaim-migrate @ 7951]
Sean Egan <seanegan@pidgin.im>
parents: 7354
diff changeset
4051 GTK_SOURCE_SEARCH_CASE_INSENSITIVE,
7295
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4052 &start, &end, NULL));
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4053 }
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4054 return TRUE;
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4055 }
14400
953baf2eba1a [gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents: 14395
diff changeset
4056 else if (!new_search)
953baf2eba1a [gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents: 14395
diff changeset
4057 {
953baf2eba1a [gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents: 14395
diff changeset
4058 /* We hit the end, so start at the beginning again. */
15093
5501dd769dc5 [gaim-migrate @ 17814]
Sean Egan <seanegan@pidgin.im>
parents: 14970
diff changeset
4059 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter);
5501dd769dc5 [gaim-migrate @ 17814]
Sean Egan <seanegan@pidgin.im>
parents: 14970
diff changeset
4060
5501dd769dc5 [gaim-migrate @ 17814]
Sean Egan <seanegan@pidgin.im>
parents: 14970
diff changeset
4061 if (gtk_source_iter_backward_search(&iter, imhtml->search_string,
14400
953baf2eba1a [gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents: 14395
diff changeset
4062 GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_CASE_INSENSITIVE,
953baf2eba1a [gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents: 14395
diff changeset
4063 &start, &end, NULL))
953baf2eba1a [gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents: 14395
diff changeset
4064 {
953baf2eba1a [gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents: 14395
diff changeset
4065 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &start, 0, TRUE, 0, 0);
15093
5501dd769dc5 [gaim-migrate @ 17814]
Sean Egan <seanegan@pidgin.im>
parents: 14970
diff changeset
4066 gtk_text_buffer_create_mark(imhtml->text_buffer, "search", &start, FALSE);
14400
953baf2eba1a [gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents: 14395
diff changeset
4067
953baf2eba1a [gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents: 14395
diff changeset
4068 return TRUE;
953baf2eba1a [gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents: 14395
diff changeset
4069 }
953baf2eba1a [gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents: 14395
diff changeset
4070
953baf2eba1a [gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents: 14395
diff changeset
4071 }
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4072
7295
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4073 return FALSE;
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4074 }
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4075
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4076 void gtk_imhtml_search_clear(GtkIMHtml *imhtml)
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4077 {
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4078 GtkTextIter start, end;
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4079
7295
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4080 g_return_if_fail(imhtml != NULL);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4081
7295
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4082 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start);
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4083 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end);
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4084
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4085 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &start, &end);
14097
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 14010
diff changeset
4086 g_free(imhtml->search_string);
7295
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4087 imhtml->search_string = NULL;
4b40d35a6b25 [gaim-migrate @ 7879]
Sean Egan <seanegan@pidgin.im>
parents: 7287
diff changeset
4088 }
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4089
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4090 static GtkTextTag *find_font_forecolor_tag(GtkIMHtml *imhtml, gchar *color)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4091 {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4092 gchar str[18];
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4093 GtkTextTag *tag;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4094
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4095 g_snprintf(str, sizeof(str), "FORECOLOR %s", color);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4096
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4097 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str);
10858
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
4098 if (!tag) {
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
4099 GdkColor gcolor;
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
4100 if (!gdk_color_parse(color, &gcolor)) {
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
4101 gchar tmp[8];
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
4102 tmp[0] = '#';
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
4103 strncpy(&tmp[1], color, 7);
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
4104 tmp[7] = '\0';
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
4105 if (!gdk_color_parse(tmp, &gcolor))
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
4106 gdk_color_parse("black", &gcolor);
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
4107 }
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
4108 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground-gdk", &gcolor, NULL);
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
4109 }
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4110
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4111 return tag;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4112 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4113
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4114 static GtkTextTag *find_font_backcolor_tag(GtkIMHtml *imhtml, gchar *color)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4115 {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4116 gchar str[18];
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4117 GtkTextTag *tag;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4118
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4119 g_snprintf(str, sizeof(str), "BACKCOLOR %s", color);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4120
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4121 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str);
10858
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
4122 if (!tag) {
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
4123 GdkColor gcolor;
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
4124 if (!gdk_color_parse(color, &gcolor)) {
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
4125 gchar tmp[8];
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
4126 tmp[0] = '#';
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
4127 strncpy(&tmp[1], color, 7);
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
4128 tmp[7] = '\0';
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
4129 if (!gdk_color_parse(tmp, &gcolor))
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
4130 gdk_color_parse("white", &gcolor);
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
4131 }
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
4132 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "background-gdk", &gcolor, NULL);
99fc7e2b9410 [gaim-migrate @ 12534]
Tim Ringenbach <marv@pidgin.im>
parents: 10857
diff changeset
4133 }
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4134
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4135 return tag;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4136 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4137
10776
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4138 static GtkTextTag *find_font_background_tag(GtkIMHtml *imhtml, gchar *color)
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4139 {
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4140 gchar str[19];
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4141 GtkTextTag *tag;
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4142
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4143 g_snprintf(str, sizeof(str), "BACKGROUND %s", color);
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4144
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4145 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str);
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4146 if (!tag)
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4147 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, NULL);
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4148
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4149 return tag;
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4150 }
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4151
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4152 static GtkTextTag *find_font_face_tag(GtkIMHtml *imhtml, gchar *face)
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4153 {
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4154 gchar str[256];
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4155 GtkTextTag *tag;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4156
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4157 g_snprintf(str, sizeof(str), "FONT FACE %s", face);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4158 str[255] = '\0';
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4159
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4160 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4161 if (!tag)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4162 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "family", face, NULL);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4163
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4164 return tag;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4165 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4166
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4167 static GtkTextTag *find_font_size_tag(GtkIMHtml *imhtml, int size)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4168 {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4169 gchar str[24];
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4170 GtkTextTag *tag;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4171
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4172 g_snprintf(str, sizeof(str), "FONT SIZE %d", size);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4173 str[23] = '\0';
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4174
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4175 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4176 if (!tag) {
10525
0f7757486d04 [gaim-migrate @ 11842]
Etan Reisner <deryni@pidgin.im>
parents: 10524
diff changeset
4177 /* For reasons I don't understand, setting "scale" here scaled
0f7757486d04 [gaim-migrate @ 11842]
Etan Reisner <deryni@pidgin.im>
parents: 10524
diff changeset
4178 * based on some default size other than my theme's default
0f7757486d04 [gaim-migrate @ 11842]
Etan Reisner <deryni@pidgin.im>
parents: 10524
diff changeset
4179 * size. Our size 4 was actually smaller than our size 3 for
0f7757486d04 [gaim-migrate @ 11842]
Etan Reisner <deryni@pidgin.im>
parents: 10524
diff changeset
4180 * me. So this works around that oddity.
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4181 */
10525
0f7757486d04 [gaim-migrate @ 11842]
Etan Reisner <deryni@pidgin.im>
parents: 10524
diff changeset
4182 GtkTextAttributes *attr = gtk_text_view_get_default_attributes(GTK_TEXT_VIEW(imhtml));
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4183 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "size",
10525
0f7757486d04 [gaim-migrate @ 11842]
Etan Reisner <deryni@pidgin.im>
parents: 10524
diff changeset
4184 (gint) (pango_font_description_get_size(attr->font) *
10899
87d9aec5b72d [gaim-migrate @ 12619]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10871
diff changeset
4185 (double) POINT_SIZE(size)), NULL);
10525
0f7757486d04 [gaim-migrate @ 11842]
Etan Reisner <deryni@pidgin.im>
parents: 10524
diff changeset
4186 gtk_text_attributes_unref(attr);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4187 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4188
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4189 return tag;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4190 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4191
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4192 static void remove_tag_by_prefix(GtkIMHtml *imhtml, const GtkTextIter *i, const GtkTextIter *e,
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4193 const char *prefix, guint len, gboolean homo)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4194 {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4195 GSList *tags, *l;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4196 GtkTextIter iter;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4197
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4198 tags = gtk_text_iter_get_tags(i);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4199
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4200 for (l = tags; l; l = l->next) {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4201 GtkTextTag *tag = l->data;
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
4202 gchar *name = NULL;
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
4203
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
4204 g_object_get(G_OBJECT(tag), "name", &name, NULL);
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
4205
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4206 if (name && !strncmp(name, prefix, len))
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4207 gtk_text_buffer_remove_tag(imhtml->text_buffer, tag, i, e);
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4208
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
4209 g_free(name);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4210 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4211
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4212 g_slist_free(tags);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4213
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4214 if (homo)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4215 return;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4216
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4217 iter = *i;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4218
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4219 while (gtk_text_iter_forward_char(&iter) && !gtk_text_iter_equal(&iter, e)) {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4220 if (gtk_text_iter_begins_tag(&iter, NULL)) {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4221 tags = gtk_text_iter_get_toggled_tags(&iter, TRUE);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4222
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4223 for (l = tags; l; l = l->next) {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4224 GtkTextTag *tag = l->data;
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
4225 gchar *name = NULL;
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
4226
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
4227 g_object_get(G_OBJECT(tag), "name", &name, NULL);
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4228
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4229 if (name && !strncmp(name, prefix, len))
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4230 gtk_text_buffer_remove_tag(imhtml->text_buffer, tag, &iter, e);
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4231
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
4232 g_free(name);
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4233 }
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4234
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4235 g_slist_free(tags);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4236 }
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4237 }
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4238 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4239
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4240 static void remove_font_size(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4241 {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4242 remove_tag_by_prefix(imhtml, i, e, "FONT SIZE ", 10, homo);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4243 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4244
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4245 static void remove_font_face(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4246 {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4247 remove_tag_by_prefix(imhtml, i, e, "FONT FACE ", 10, homo);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4248 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4249
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4250 static void remove_font_forecolor(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4251 {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4252 remove_tag_by_prefix(imhtml, i, e, "FORECOLOR ", 10, homo);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4253 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4254
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4255 static void remove_font_backcolor(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4256 {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4257 remove_tag_by_prefix(imhtml, i, e, "BACKCOLOR ", 10, homo);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4258 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4259
10776
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4260 static void remove_font_background(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo)
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4261 {
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4262 remove_tag_by_prefix(imhtml, i, e, "BACKGROUND ", 10, homo);
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4263 }
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4264
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4265 static void remove_font_link(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4266 {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4267 remove_tag_by_prefix(imhtml, i, e, "LINK ", 5, homo);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4268 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4269
12672
673e2a1d2954 [gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12635
diff changeset
4270 static void
673e2a1d2954 [gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12635
diff changeset
4271 imhtml_clear_formatting(GtkIMHtml *imhtml)
673e2a1d2954 [gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12635
diff changeset
4272 {
673e2a1d2954 [gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12635
diff changeset
4273 GtkTextIter start, end;
673e2a1d2954 [gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12635
diff changeset
4274
12796
8fb3611a91e1 [gaim-migrate @ 15143]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12673
diff changeset
4275 if (!imhtml->editable)
8fb3611a91e1 [gaim-migrate @ 15143]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12673
diff changeset
4276 return;
8fb3611a91e1 [gaim-migrate @ 15143]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12673
diff changeset
4277
28935
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4278 if (!imhtml_get_iter_bounds(imhtml, &start, &end))
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4279 return;
12672
673e2a1d2954 [gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12635
diff changeset
4280
673e2a1d2954 [gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12635
diff changeset
4281 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end);
673e2a1d2954 [gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12635
diff changeset
4282 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end);
673e2a1d2954 [gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12635
diff changeset
4283 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end);
673e2a1d2954 [gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12635
diff changeset
4284 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end);
13224
485977c61b47 [gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents: 13138
diff changeset
4285 remove_font_size(imhtml, &start, &end, FALSE);
485977c61b47 [gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents: 13138
diff changeset
4286 remove_font_face(imhtml, &start, &end, FALSE);
485977c61b47 [gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents: 13138
diff changeset
4287 remove_font_forecolor(imhtml, &start, &end, FALSE);
485977c61b47 [gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents: 13138
diff changeset
4288 remove_font_backcolor(imhtml, &start, &end, FALSE);
485977c61b47 [gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents: 13138
diff changeset
4289 remove_font_background(imhtml, &start, &end, FALSE);
485977c61b47 [gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents: 13138
diff changeset
4290 remove_font_link(imhtml, &start, &end, FALSE);
12672
673e2a1d2954 [gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12635
diff changeset
4291
673e2a1d2954 [gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12635
diff changeset
4292 imhtml->edit.bold = 0;
673e2a1d2954 [gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12635
diff changeset
4293 imhtml->edit.italic = 0;
673e2a1d2954 [gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12635
diff changeset
4294 imhtml->edit.underline = 0;
673e2a1d2954 [gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12635
diff changeset
4295 imhtml->edit.strike = 0;
673e2a1d2954 [gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12635
diff changeset
4296 imhtml->edit.fontsize = 0;
13224
485977c61b47 [gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents: 13138
diff changeset
4297
485977c61b47 [gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents: 13138
diff changeset
4298 g_free(imhtml->edit.fontface);
485977c61b47 [gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents: 13138
diff changeset
4299 imhtml->edit.fontface = NULL;
485977c61b47 [gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents: 13138
diff changeset
4300
485977c61b47 [gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents: 13138
diff changeset
4301 g_free(imhtml->edit.forecolor);
12672
673e2a1d2954 [gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12635
diff changeset
4302 imhtml->edit.forecolor = NULL;
13224
485977c61b47 [gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents: 13138
diff changeset
4303
485977c61b47 [gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents: 13138
diff changeset
4304 g_free(imhtml->edit.backcolor);
12672
673e2a1d2954 [gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12635
diff changeset
4305 imhtml->edit.backcolor = NULL;
13224
485977c61b47 [gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents: 13138
diff changeset
4306
485977c61b47 [gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents: 13138
diff changeset
4307 g_free(imhtml->edit.background);
12672
673e2a1d2954 [gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12635
diff changeset
4308 imhtml->edit.background = NULL;
673e2a1d2954 [gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12635
diff changeset
4309 }
673e2a1d2954 [gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12635
diff changeset
4310
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4311 /* Editable stuff */
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4312 static void preinsert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4313 {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4314 imhtml->insert_offset = gtk_text_iter_get_offset(iter);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4315 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4316
10169
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4317 static void insert_ca_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextChildAnchor *arg2, gpointer user_data)
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4318 {
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4319 GtkTextIter start;
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4320
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4321 start = *arg1;
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4322 gtk_text_iter_backward_char(&start);
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4323
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4324 gtk_imhtml_apply_tags_on_insert(user_data, &start, arg1);
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4325 }
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4326
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4327 static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *end, gchar *text, gint len, GtkIMHtml *imhtml)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4328 {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4329 GtkTextIter start;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4330
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4331 if (!len)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4332 return;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4333
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4334 start = *end;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4335 gtk_text_iter_set_offset(&start, imhtml->insert_offset);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4336
10169
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4337 gtk_imhtml_apply_tags_on_insert(imhtml, &start, end);
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4338 }
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4339
12673
4c8a20955e0b [gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12672
diff changeset
4340 static void delete_cb(GtkTextBuffer *buffer, GtkTextIter *start, GtkTextIter *end, GtkIMHtml *imhtml)
4c8a20955e0b [gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12672
diff changeset
4341 {
4c8a20955e0b [gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12672
diff changeset
4342 GSList *tags, *l;
4c8a20955e0b [gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12672
diff changeset
4343
4c8a20955e0b [gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12672
diff changeset
4344 tags = gtk_text_iter_get_tags(start);
4c8a20955e0b [gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12672
diff changeset
4345 for (l = tags; l != NULL; l = l->next) {
4c8a20955e0b [gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12672
diff changeset
4346 GtkTextTag *tag = GTK_TEXT_TAG(l->data);
4c8a20955e0b [gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12672
diff changeset
4347
4c8a20955e0b [gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12672
diff changeset
4348 if (tag && /* Remove the formatting only if */
4c8a20955e0b [gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12672
diff changeset
4349 gtk_text_iter_starts_word(start) && /* beginning of a word */
4c8a20955e0b [gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12672
diff changeset
4350 gtk_text_iter_begins_tag(start, tag) && /* the tag starts with the selection */
4c8a20955e0b [gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12672
diff changeset
4351 (!gtk_text_iter_has_tag(end, tag) || /* the tag ends within the selection */
4c8a20955e0b [gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12672
diff changeset
4352 gtk_text_iter_ends_tag(end, tag))) {
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
4353 gchar *name = NULL;
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
4354
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
4355 g_object_get(G_OBJECT(tag), "name", &name, NULL);
12673
4c8a20955e0b [gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12672
diff changeset
4356 gtk_text_buffer_remove_tag(imhtml->text_buffer, tag, start, end);
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4357
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
4358 if (name && strncmp(name, "LINK ", 5) == 0 && imhtml->edit.link) {
12673
4c8a20955e0b [gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12672
diff changeset
4359 gtk_imhtml_toggle_link(imhtml, NULL);
4c8a20955e0b [gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12672
diff changeset
4360 }
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4361
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
4362 g_free(name);
14097
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 14010
diff changeset
4363 }
12673
4c8a20955e0b [gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12672
diff changeset
4364 }
4c8a20955e0b [gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12672
diff changeset
4365 g_slist_free(tags);
4c8a20955e0b [gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12672
diff changeset
4366 }
4c8a20955e0b [gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12672
diff changeset
4367
10169
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4368 static void gtk_imhtml_apply_tags_on_insert(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end)
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4369 {
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4370 if (imhtml->edit.bold)
10169
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4371 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", start, end);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4372 else
10169
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4373 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", start, end);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4374
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4375 if (imhtml->edit.italic)
10169
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4376 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", start, end);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4377 else
10169
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4378 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", start, end);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4379
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4380 if (imhtml->edit.underline)
10169
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4381 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", start, end);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4382 else
10169
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4383 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", start, end);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4384
9924
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4385 if (imhtml->edit.strike)
10169
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4386 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", start, end);
9924
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4387 else
10169
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4388 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", start, end);
9924
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4389
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4390 if (imhtml->edit.forecolor) {
10169
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4391 remove_font_forecolor(imhtml, start, end, TRUE);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4392 gtk_text_buffer_apply_tag(imhtml->text_buffer,
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4393 find_font_forecolor_tag(imhtml, imhtml->edit.forecolor),
10169
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4394 start, end);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4395 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4396
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4397 if (imhtml->edit.backcolor) {
10169
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4398 remove_font_backcolor(imhtml, start, end, TRUE);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4399 gtk_text_buffer_apply_tag(imhtml->text_buffer,
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4400 find_font_backcolor_tag(imhtml, imhtml->edit.backcolor),
10169
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4401 start, end);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4402 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4403
10776
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4404 if (imhtml->edit.background) {
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4405 remove_font_background(imhtml, start, end, TRUE);
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4406 gtk_text_buffer_apply_tag(imhtml->text_buffer,
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4407 find_font_background_tag(imhtml, imhtml->edit.background),
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4408 start, end);
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4409 }
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4410 if (imhtml->edit.fontface) {
10169
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4411 remove_font_face(imhtml, start, end, TRUE);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4412 gtk_text_buffer_apply_tag(imhtml->text_buffer,
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4413 find_font_face_tag(imhtml, imhtml->edit.fontface),
10169
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4414 start, end);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4415 }
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4416
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4417 if (imhtml->edit.fontsize) {
10169
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4418 remove_font_size(imhtml, start, end, TRUE);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4419 gtk_text_buffer_apply_tag(imhtml->text_buffer,
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4420 find_font_size_tag(imhtml, imhtml->edit.fontsize),
10169
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4421 start, end);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4422 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4423
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4424 if (imhtml->edit.link) {
10169
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4425 remove_font_link(imhtml, start, end, TRUE);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4426 gtk_text_buffer_apply_tag(imhtml->text_buffer,
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4427 imhtml->edit.link,
10169
cdf48befaa8a [gaim-migrate @ 11258]
Tim Ringenbach <marv@pidgin.im>
parents: 10165
diff changeset
4428 start, end);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4429 }
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4430 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4431
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4432 void gtk_imhtml_set_editable(GtkIMHtml *imhtml, gboolean editable)
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4433 {
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4434 gtk_text_view_set_editable(GTK_TEXT_VIEW(imhtml), editable);
8177
33b3a01c6318 [gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents: 8149
diff changeset
4435 /*
33b3a01c6318 [gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents: 8149
diff changeset
4436 * We need a visible caret for accessibility, so mouseless
33b3a01c6318 [gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents: 8149
diff changeset
4437 * people can highlight stuff.
33b3a01c6318 [gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents: 8149
diff changeset
4438 */
33b3a01c6318 [gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents: 8149
diff changeset
4439 /* gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(imhtml), editable); */
27031
6779a535047e Avoid adding several callbacks on repeated invocations of gtk_imhtml_set_editable.
Daniel Atallah <datallah@pidgin.im>
parents: 26829
diff changeset
4440 if (editable && !imhtml->editable) {
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4441 g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set",
21765
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
4442 G_CALLBACK(mark_set_cb), imhtml);
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
4443 g_signal_connect(G_OBJECT(imhtml), "backspace", G_CALLBACK(smart_backspace_cb), NULL);
27031
6779a535047e Avoid adding several callbacks on repeated invocations of gtk_imhtml_set_editable.
Daniel Atallah <datallah@pidgin.im>
parents: 26829
diff changeset
4444 } else if (!editable && imhtml->editable) {
6779a535047e Avoid adding several callbacks on repeated invocations of gtk_imhtml_set_editable.
Daniel Atallah <datallah@pidgin.im>
parents: 26829
diff changeset
4445 g_signal_handlers_disconnect_by_func(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer),
6779a535047e Avoid adding several callbacks on repeated invocations of gtk_imhtml_set_editable.
Daniel Atallah <datallah@pidgin.im>
parents: 26829
diff changeset
4446 mark_set_cb, imhtml);
6779a535047e Avoid adding several callbacks on repeated invocations of gtk_imhtml_set_editable.
Daniel Atallah <datallah@pidgin.im>
parents: 26829
diff changeset
4447 g_signal_handlers_disconnect_by_func(G_OBJECT(imhtml),
6779a535047e Avoid adding several callbacks on repeated invocations of gtk_imhtml_set_editable.
Daniel Atallah <datallah@pidgin.im>
parents: 26829
diff changeset
4448 smart_backspace_cb, NULL);
21765
b9271e416f6d Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21644
diff changeset
4449 }
27031
6779a535047e Avoid adding several callbacks on repeated invocations of gtk_imhtml_set_editable.
Daniel Atallah <datallah@pidgin.im>
parents: 26829
diff changeset
4450
6779a535047e Avoid adding several callbacks on repeated invocations of gtk_imhtml_set_editable.
Daniel Atallah <datallah@pidgin.im>
parents: 26829
diff changeset
4451 imhtml->editable = editable;
6779a535047e Avoid adding several callbacks on repeated invocations of gtk_imhtml_set_editable.
Daniel Atallah <datallah@pidgin.im>
parents: 26829
diff changeset
4452 imhtml->format_functions = GTK_IMHTML_ALL;
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4453 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4454
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4455 void gtk_imhtml_set_whole_buffer_formatting_only(GtkIMHtml *imhtml, gboolean wbfo)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4456 {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4457 g_return_if_fail(imhtml != NULL);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4458
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4459 imhtml->wbfo = wbfo;
8420
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
4460 }
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
4461
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
4462 void gtk_imhtml_set_format_functions(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons)
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
4463 {
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
4464 GObject *object = g_object_ref(G_OBJECT(imhtml));
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4465 imhtml->format_functions = buttons;
8420
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
4466 g_signal_emit(object, signals[BUTTONS_UPDATE], 0, buttons);
71d59c4e2beb [gaim-migrate @ 9150]
Sean Egan <seanegan@pidgin.im>
parents: 8380
diff changeset
4467 g_object_unref(object);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4468 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4469
8788
a13634443a38 [gaim-migrate @ 9550]
Mark Doliner <markdoliner@pidgin.im>
parents: 8786
diff changeset
4470 GtkIMHtmlButtons gtk_imhtml_get_format_functions(GtkIMHtml *imhtml)
a13634443a38 [gaim-migrate @ 9550]
Mark Doliner <markdoliner@pidgin.im>
parents: 8786
diff changeset
4471 {
a13634443a38 [gaim-migrate @ 9550]
Mark Doliner <markdoliner@pidgin.im>
parents: 8786
diff changeset
4472 return imhtml->format_functions;
a13634443a38 [gaim-migrate @ 9550]
Mark Doliner <markdoliner@pidgin.im>
parents: 8786
diff changeset
4473 }
8516
a29b503cdfa0 [gaim-migrate @ 9254]
Gary Kramlich <grim@pidgin.im>
parents: 8515
diff changeset
4474
a29b503cdfa0 [gaim-migrate @ 9254]
Gary Kramlich <grim@pidgin.im>
parents: 8515
diff changeset
4475 void gtk_imhtml_get_current_format(GtkIMHtml *imhtml, gboolean *bold,
a29b503cdfa0 [gaim-migrate @ 9254]
Gary Kramlich <grim@pidgin.im>
parents: 8515
diff changeset
4476 gboolean *italic, gboolean *underline)
8481
7a9eb76e8eee [gaim-migrate @ 9214]
Gary Kramlich <grim@pidgin.im>
parents: 8473
diff changeset
4477 {
12900
7fe519669e07 [gaim-migrate @ 15253]
Richard Laager <rlaager@pidgin.im>
parents: 12836
diff changeset
4478 if (bold != NULL)
7fe519669e07 [gaim-migrate @ 15253]
Richard Laager <rlaager@pidgin.im>
parents: 12836
diff changeset
4479 (*bold) = imhtml->edit.bold;
7fe519669e07 [gaim-migrate @ 15253]
Richard Laager <rlaager@pidgin.im>
parents: 12836
diff changeset
4480 if (italic != NULL)
7fe519669e07 [gaim-migrate @ 15253]
Richard Laager <rlaager@pidgin.im>
parents: 12836
diff changeset
4481 (*italic) = imhtml->edit.italic;
7fe519669e07 [gaim-migrate @ 15253]
Richard Laager <rlaager@pidgin.im>
parents: 12836
diff changeset
4482 if (underline != NULL)
7fe519669e07 [gaim-migrate @ 15253]
Richard Laager <rlaager@pidgin.im>
parents: 12836
diff changeset
4483 (*underline) = imhtml->edit.underline;
8481
7a9eb76e8eee [gaim-migrate @ 9214]
Gary Kramlich <grim@pidgin.im>
parents: 8473
diff changeset
4484 }
7a9eb76e8eee [gaim-migrate @ 9214]
Gary Kramlich <grim@pidgin.im>
parents: 8473
diff changeset
4485
9025
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4486 char *
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4487 gtk_imhtml_get_current_fontface(GtkIMHtml *imhtml)
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4488 {
14097
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 14010
diff changeset
4489 return g_strdup(imhtml->edit.fontface);
9025
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4490 }
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4491
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4492 char *
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4493 gtk_imhtml_get_current_forecolor(GtkIMHtml *imhtml)
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4494 {
14097
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 14010
diff changeset
4495 return g_strdup(imhtml->edit.forecolor);
9025
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4496 }
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4497
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4498 char *
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4499 gtk_imhtml_get_current_backcolor(GtkIMHtml *imhtml)
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4500 {
14097
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 14010
diff changeset
4501 return g_strdup(imhtml->edit.backcolor);
9025
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4502 }
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4503
11267
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4504 char *
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4505 gtk_imhtml_get_current_background(GtkIMHtml *imhtml)
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4506 {
14097
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 14010
diff changeset
4507 return g_strdup(imhtml->edit.background);
11267
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4508 }
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4509
9025
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4510 gint
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4511 gtk_imhtml_get_current_fontsize(GtkIMHtml *imhtml)
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4512 {
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4513 return imhtml->edit.fontsize;
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4514 }
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4515
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4516 gboolean gtk_imhtml_get_editable(GtkIMHtml *imhtml)
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4517 {
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4518 return imhtml->editable;
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4519 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4520
11269
ca63789d57b9 [gaim-migrate @ 13451]
Richard Laager <rlaager@pidgin.im>
parents: 11267
diff changeset
4521 void
ca63789d57b9 [gaim-migrate @ 13451]
Richard Laager <rlaager@pidgin.im>
parents: 11267
diff changeset
4522 gtk_imhtml_clear_formatting(GtkIMHtml *imhtml)
ca63789d57b9 [gaim-migrate @ 13451]
Richard Laager <rlaager@pidgin.im>
parents: 11267
diff changeset
4523 {
11275
cdcc651d7ecd [gaim-migrate @ 13461]
Richard Laager <rlaager@pidgin.im>
parents: 11269
diff changeset
4524 GObject *object;
cdcc651d7ecd [gaim-migrate @ 13461]
Richard Laager <rlaager@pidgin.im>
parents: 11269
diff changeset
4525
cdcc651d7ecd [gaim-migrate @ 13461]
Richard Laager <rlaager@pidgin.im>
parents: 11269
diff changeset
4526 object = g_object_ref(G_OBJECT(imhtml));
cdcc651d7ecd [gaim-migrate @ 13461]
Richard Laager <rlaager@pidgin.im>
parents: 11269
diff changeset
4527 g_signal_emit(object, signals[CLEAR_FORMAT], 0);
11276
aec923529d31 [gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents: 11275
diff changeset
4528
11269
ca63789d57b9 [gaim-migrate @ 13451]
Richard Laager <rlaager@pidgin.im>
parents: 11267
diff changeset
4529 gtk_widget_grab_focus(GTK_WIDGET(imhtml));
11276
aec923529d31 [gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents: 11275
diff changeset
4530
aec923529d31 [gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents: 11275
diff changeset
4531 g_object_unref(object);
11269
ca63789d57b9 [gaim-migrate @ 13451]
Richard Laager <rlaager@pidgin.im>
parents: 11267
diff changeset
4532 }
ca63789d57b9 [gaim-migrate @ 13451]
Richard Laager <rlaager@pidgin.im>
parents: 11267
diff changeset
4533
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4534 /*
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4535 * I had this crazy idea about changing the text cursor color to reflex the foreground color
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4536 * of the text about to be entered. This is the place you'd do it, along with the place where
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4537 * we actually set a new foreground color.
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15865
diff changeset
4538 * I may not do this, because people will bitch about Purple overriding their gtk theme's cursor
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4539 * colors.
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4540 *
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4541 * Just in case I do do this, I asked about what to set the secondary text cursor to.
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4542 *
8719
1d1a4e11b4ab [gaim-migrate @ 9474]
Tim Ringenbach <marv@pidgin.im>
parents: 8707
diff changeset
4543 * (12:45:27) ?? ???: secondary_cursor_color = (rgb(background) + rgb(primary_cursor_color) ) / 2
1d1a4e11b4ab [gaim-migrate @ 9474]
Tim Ringenbach <marv@pidgin.im>
parents: 8707
diff changeset
4544 * (12:45:55) ?? ???: understand?
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4545 * (12:46:14) Tim: yeah. i didn't know there was an exact formula
8735
01248ea222d3 [gaim-migrate @ 9490]
Jonathan Champ <royanee@users.sourceforge.net>
parents: 8729
diff changeset
4546 * (12:46:56) ?? ???: u might need to extract separate each color from RGB
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4547 */
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4548
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4549 static void mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark,
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4550 GtkIMHtml *imhtml)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4551 {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4552 GSList *tags, *l;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4553 GtkTextIter iter;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4554
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4555 if (mark != gtk_text_buffer_get_insert(buffer))
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4556 return;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4557
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4558 if (!gtk_text_buffer_get_char_count(buffer))
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4559 return;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4560
9924
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4561 imhtml->edit.bold = imhtml->edit.italic = imhtml->edit.underline = imhtml->edit.strike = FALSE;
14097
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 14010
diff changeset
4562 g_free(imhtml->edit.forecolor);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4563 imhtml->edit.forecolor = NULL;
14097
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 14010
diff changeset
4564
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 14010
diff changeset
4565 g_free(imhtml->edit.backcolor);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4566 imhtml->edit.backcolor = NULL;
14097
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 14010
diff changeset
4567
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 14010
diff changeset
4568 g_free(imhtml->edit.fontface);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4569 imhtml->edit.fontface = NULL;
14097
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 14010
diff changeset
4570
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4571 imhtml->edit.fontsize = 0;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4572 imhtml->edit.link = NULL;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4573
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4574 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4575
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4576
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4577 if (gtk_text_iter_is_end(&iter))
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4578 tags = gtk_text_iter_get_toggled_tags(&iter, FALSE);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4579 else
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4580 tags = gtk_text_iter_get_tags(&iter);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4581
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4582 for (l = tags; l != NULL; l = l->next) {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4583 GtkTextTag *tag = GTK_TEXT_TAG(l->data);
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
4584 gchar *name = NULL;
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
4585
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
4586 g_object_get(G_OBJECT(tag), "name", &name, NULL);
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
4587
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4588 if (name) {
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4589 if (strcmp(name, "BOLD") == 0)
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4590 imhtml->edit.bold = TRUE;
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4591 else if (strcmp(name, "ITALICS") == 0)
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4592 imhtml->edit.italic = TRUE;
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4593 else if (strcmp(name, "UNDERLINE") == 0)
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4594 imhtml->edit.underline = TRUE;
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4595 else if (strcmp(name, "STRIKE") == 0)
9924
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4596 imhtml->edit.strike = TRUE;
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4597 else if (strncmp(name, "FORECOLOR ", 10) == 0)
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4598 imhtml->edit.forecolor = g_strdup(&(name)[10]);
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4599 else if (strncmp(name, "BACKCOLOR ", 10) == 0)
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4600 imhtml->edit.backcolor = g_strdup(&(name)[10]);
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4601 else if (strncmp(name, "FONT FACE ", 10) == 0)
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4602 imhtml->edit.fontface = g_strdup(&(name)[10]);
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4603 else if (strncmp(name, "FONT SIZE ", 10) == 0)
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4604 imhtml->edit.fontsize = strtol(&(name)[10], NULL, 10);
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4605 else if ((strncmp(name, "LINK ", 5) == 0) && !gtk_text_iter_is_end(&iter))
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4606 imhtml->edit.link = tag;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4607 }
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4608
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
4609 g_free(name);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4610 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4611
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4612 g_slist_free(tags);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4613 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4614
12605
7390627a6aaf [gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents: 12600
diff changeset
4615 static void imhtml_emit_signal_for_format(GtkIMHtml *imhtml, GtkIMHtmlButtons button)
7390627a6aaf [gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents: 12600
diff changeset
4616 {
7390627a6aaf [gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents: 12600
diff changeset
4617 GObject *object;
7390627a6aaf [gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents: 12600
diff changeset
4618
7390627a6aaf [gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents: 12600
diff changeset
4619 g_return_if_fail(imhtml != NULL);
7390627a6aaf [gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents: 12600
diff changeset
4620
7390627a6aaf [gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents: 12600
diff changeset
4621 object = g_object_ref(G_OBJECT(imhtml));
7390627a6aaf [gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents: 12600
diff changeset
4622 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, button);
7390627a6aaf [gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents: 12600
diff changeset
4623 g_object_unref(object);
7390627a6aaf [gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents: 12600
diff changeset
4624 }
7390627a6aaf [gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents: 12600
diff changeset
4625
11267
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4626 static void imhtml_toggle_bold(GtkIMHtml *imhtml)
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4627 {
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4628 GtkTextIter start, end;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4629
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4630 imhtml->edit.bold = !imhtml->edit.bold;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4631
28935
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4632 if (!imhtml_get_iter_bounds(imhtml, &start, &end))
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4633 return;
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4634
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4635 if (imhtml->edit.bold)
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4636 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end);
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4637 else
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4638 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4639 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4640
11267
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4641 void gtk_imhtml_toggle_bold(GtkIMHtml *imhtml)
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4642 {
12605
7390627a6aaf [gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents: 12600
diff changeset
4643 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_BOLD);
11267
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4644 }
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4645
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4646 static void imhtml_toggle_italic(GtkIMHtml *imhtml)
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4647 {
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4648 GtkTextIter start, end;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4649
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4650 imhtml->edit.italic = !imhtml->edit.italic;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4651
28935
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4652 if (!imhtml_get_iter_bounds(imhtml, &start, &end))
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4653 return;
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4654
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4655 if (imhtml->edit.italic)
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4656 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end);
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4657 else
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4658 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4659 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4660
11267
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4661 void gtk_imhtml_toggle_italic(GtkIMHtml *imhtml)
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4662 {
12605
7390627a6aaf [gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents: 12600
diff changeset
4663 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_ITALIC);
7390627a6aaf [gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents: 12600
diff changeset
4664 }
11267
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4665
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4666 static void imhtml_toggle_underline(GtkIMHtml *imhtml)
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4667 {
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4668 GtkTextIter start, end;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4669
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4670 imhtml->edit.underline = !imhtml->edit.underline;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4671
28935
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4672 if (!imhtml_get_iter_bounds(imhtml, &start, &end))
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4673 return;
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4674
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4675 if (imhtml->edit.underline)
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4676 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end);
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4677 else
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4678 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4679 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4680
11267
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4681 void gtk_imhtml_toggle_underline(GtkIMHtml *imhtml)
9924
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4682 {
12605
7390627a6aaf [gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents: 12600
diff changeset
4683 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_UNDERLINE);
11267
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4684 }
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4685
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4686 static void imhtml_toggle_strike(GtkIMHtml *imhtml)
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4687 {
9924
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4688 GtkTextIter start, end;
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4689
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4690 imhtml->edit.strike = !imhtml->edit.strike;
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4691
28935
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4692 if (!imhtml_get_iter_bounds(imhtml, &start, &end))
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4693 return;
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4694
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4695 if (imhtml->edit.strike)
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4696 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end);
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4697 else
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4698 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end);
11267
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4699 }
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4700
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4701 void gtk_imhtml_toggle_strike(GtkIMHtml *imhtml)
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4702 {
12605
7390627a6aaf [gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents: 12600
diff changeset
4703 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_STRIKE);
9924
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4704 }
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
4705
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4706 void gtk_imhtml_font_set_size(GtkIMHtml *imhtml, gint size)
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4707 {
9025
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4708 GObject *object;
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4709 GtkTextIter start, end;
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4710
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4711 imhtml->edit.fontsize = size;
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4712
28935
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4713 if (!imhtml_get_iter_bounds(imhtml, &start, &end))
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4714 return;
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4715
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4716 remove_font_size(imhtml, &start, &end, imhtml->wbfo);
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4717 gtk_text_buffer_apply_tag(imhtml->text_buffer,
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4718 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4719
9025
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4720 object = g_object_ref(G_OBJECT(imhtml));
11267
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4721 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_SHRINK | GTK_IMHTML_GROW);
9025
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4722 g_object_unref(object);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4723 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4724
11267
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4725 static void imhtml_font_shrink(GtkIMHtml *imhtml)
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4726 {
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4727 GtkTextIter start, end;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4728
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4729 if (imhtml->edit.fontsize == 1)
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4730 return;
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4731
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4732 if (!imhtml->edit.fontsize)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4733 imhtml->edit.fontsize = 2;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4734 else
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4735 imhtml->edit.fontsize--;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4736
28935
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4737 if (!imhtml_get_iter_bounds(imhtml, &start, &end))
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4738 return;
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4739 remove_font_size(imhtml, &start, &end, imhtml->wbfo);
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4740 gtk_text_buffer_apply_tag(imhtml->text_buffer,
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4741 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end);
11267
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4742 }
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4743
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4744 void gtk_imhtml_font_shrink(GtkIMHtml *imhtml)
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4745 {
12605
7390627a6aaf [gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents: 12600
diff changeset
4746 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_SHRINK);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4747 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4748
11267
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4749 static void imhtml_font_grow(GtkIMHtml *imhtml)
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4750 {
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4751 GtkTextIter start, end;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4752
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4753 if (imhtml->edit.fontsize == MAX_FONT_SIZE)
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4754 return;
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4755
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4756 if (!imhtml->edit.fontsize)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4757 imhtml->edit.fontsize = 4;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4758 else
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4759 imhtml->edit.fontsize++;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4760
28935
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4761 if (!imhtml_get_iter_bounds(imhtml, &start, &end))
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4762 return;
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4763 remove_font_size(imhtml, &start, &end, imhtml->wbfo);
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4764 gtk_text_buffer_apply_tag(imhtml->text_buffer,
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4765 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end);
11267
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4766 }
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4767
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4768 void gtk_imhtml_font_grow(GtkIMHtml *imhtml)
78f1eb5b3d6e [gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents: 11240
diff changeset
4769 {
12605
7390627a6aaf [gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents: 12600
diff changeset
4770 imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_GROW);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4771 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4772
13225
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4773 static gboolean gtk_imhtml_toggle_str_tag(GtkIMHtml *imhtml, const char *value, char **edit_field,
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4774 void (*remove_func)(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo),
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4775 GtkTextTag *(find_func)(GtkIMHtml *imhtml, gchar *color), GtkIMHtmlButtons button)
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4776 {
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4777 GObject *object;
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4778 GtkTextIter start;
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4779 GtkTextIter end;
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4780
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4781 g_free(*edit_field);
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4782 *edit_field = NULL;
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4783
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4784 if (value && strcmp(value, "") != 0)
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4785 {
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4786 *edit_field = g_strdup(value);
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4787
28935
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4788 if (imhtml_get_iter_bounds(imhtml, &start, &end)) {
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4789 remove_func(imhtml, &start, &end, imhtml->wbfo);
13225
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4790 gtk_text_buffer_apply_tag(imhtml->text_buffer,
28935
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4791 find_func(imhtml, *edit_field), &start, &end);
13225
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4792 }
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4793 }
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4794 else
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4795 {
28935
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4796 if (imhtml_get_iter_bounds(imhtml, &start, &end))
84dbc0ca215d Remove a bunch of code duplication.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28932
diff changeset
4797 remove_func(imhtml, &start, &end, TRUE); /* 'TRUE' or 'imhtml->wbfo'? */
13225
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4798 }
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4799
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4800 object = g_object_ref(G_OBJECT(imhtml));
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4801 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, button);
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4802 g_object_unref(object);
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4803
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4804 return *edit_field != NULL;
10776
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4805 }
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4806
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4807 gboolean gtk_imhtml_toggle_forecolor(GtkIMHtml *imhtml, const char *color)
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4808 {
13225
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4809 return gtk_imhtml_toggle_str_tag(imhtml, color, &imhtml->edit.forecolor,
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4810 remove_font_forecolor, find_font_forecolor_tag,
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4811 GTK_IMHTML_FORECOLOR);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4812 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4813
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4814 gboolean gtk_imhtml_toggle_backcolor(GtkIMHtml *imhtml, const char *color)
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4815 {
13225
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4816 return gtk_imhtml_toggle_str_tag(imhtml, color, &imhtml->edit.backcolor,
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4817 remove_font_backcolor, find_font_backcolor_tag,
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4818 GTK_IMHTML_BACKCOLOR);
10776
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4819 }
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4820
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4821 gboolean gtk_imhtml_toggle_background(GtkIMHtml *imhtml, const char *color)
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
4822 {
13225
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4823 return gtk_imhtml_toggle_str_tag(imhtml, color, &imhtml->edit.background,
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4824 remove_font_background, find_font_background_tag,
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4825 GTK_IMHTML_BACKGROUND);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4826 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4827
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4828 gboolean gtk_imhtml_toggle_fontface(GtkIMHtml *imhtml, const char *face)
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4829 {
13225
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4830 return gtk_imhtml_toggle_str_tag(imhtml, face, &imhtml->edit.fontface,
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4831 remove_font_face, find_font_face_tag,
b82e04c17537 [gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents: 13224
diff changeset
4832 GTK_IMHTML_FACE);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4833 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4834
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4835 void gtk_imhtml_toggle_link(GtkIMHtml *imhtml, const char *url)
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4836 {
9025
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4837 GObject *object;
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4838 GtkTextIter start, end;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4839 GtkTextTag *linktag;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4840 static guint linkno = 0;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4841 gchar str[48];
9007
87c8402bc0e3 [gaim-migrate @ 9783]
Tim Ringenbach <marv@pidgin.im>
parents: 8962
diff changeset
4842 GdkColor *color = NULL;
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4843
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4844 imhtml->edit.link = NULL;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4845
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4846 if (url) {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4847 g_snprintf(str, sizeof(str), "LINK %d", linkno++);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4848 str[47] = '\0';
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4849
9007
87c8402bc0e3 [gaim-migrate @ 9783]
Tim Ringenbach <marv@pidgin.im>
parents: 8962
diff changeset
4850 gtk_widget_style_get(GTK_WIDGET(imhtml), "hyperlink-color", &color, NULL);
9008
0be1d8921114 [gaim-migrate @ 9784]
Tim Ringenbach <marv@pidgin.im>
parents: 9007
diff changeset
4851 if (color) {
9007
87c8402bc0e3 [gaim-migrate @ 9783]
Tim Ringenbach <marv@pidgin.im>
parents: 8962
diff changeset
4852 imhtml->edit.link = linktag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground-gdk", color, "underline", PANGO_UNDERLINE_SINGLE, NULL);
9008
0be1d8921114 [gaim-migrate @ 9784]
Tim Ringenbach <marv@pidgin.im>
parents: 9007
diff changeset
4853 gdk_color_free(color);
0be1d8921114 [gaim-migrate @ 9784]
Tim Ringenbach <marv@pidgin.im>
parents: 9007
diff changeset
4854 } else {
9007
87c8402bc0e3 [gaim-migrate @ 9783]
Tim Ringenbach <marv@pidgin.im>
parents: 8962
diff changeset
4855 imhtml->edit.link = linktag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL);
9008
0be1d8921114 [gaim-migrate @ 9784]
Tim Ringenbach <marv@pidgin.im>
parents: 9007
diff changeset
4856 }
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4857 g_object_set_data_full(G_OBJECT(linktag), "link_url", g_strdup(url), g_free);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4858 g_signal_connect(G_OBJECT(linktag), "event", G_CALLBACK(tag_event), NULL);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4859
11276
aec923529d31 [gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents: 11275
diff changeset
4860 if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4861 remove_font_link(imhtml, &start, &end, FALSE);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4862 gtk_text_buffer_apply_tag(imhtml->text_buffer, linktag, &start, &end);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4863 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4864 }
9025
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4865
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4866 object = g_object_ref(G_OBJECT(imhtml));
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4867 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_LINK);
e49a72896270 [gaim-migrate @ 9801]
Luke Schierer <lschiere@pidgin.im>
parents: 9008
diff changeset
4868 g_object_unref(object);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4869 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4870
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4871 void gtk_imhtml_insert_link(GtkIMHtml *imhtml, GtkTextMark *mark, const char *url, const char *text)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4872 {
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4873 GtkTextIter iter;
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4874
25899
da25a7ed382e The first thing gtk_text_buffer_delete_selection does is call
Mark Doliner <markdoliner@pidgin.im>
parents: 25888
diff changeset
4875 /* Delete any currently selected text */
da25a7ed382e The first thing gtk_text_buffer_delete_selection does is call
Mark Doliner <markdoliner@pidgin.im>
parents: 25888
diff changeset
4876 gtk_text_buffer_delete_selection(imhtml->text_buffer, TRUE, TRUE);
9599
1089c73e0586 [gaim-migrate @ 10442]
Tim Ringenbach <marv@pidgin.im>
parents: 9574
diff changeset
4877
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4878 gtk_imhtml_toggle_link(imhtml, url);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4879 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4880 gtk_text_buffer_insert(imhtml->text_buffer, &iter, text, -1);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4881 gtk_imhtml_toggle_link(imhtml, NULL);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4882 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4883
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4884 void gtk_imhtml_insert_smiley(GtkIMHtml *imhtml, const char *sml, char *smiley)
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4885 {
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4886 GtkTextMark *mark;
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4887 GtkTextIter iter;
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4888
25899
da25a7ed382e The first thing gtk_text_buffer_delete_selection does is call
Mark Doliner <markdoliner@pidgin.im>
parents: 25888
diff changeset
4889 /* Delete any currently selected text */
da25a7ed382e The first thing gtk_text_buffer_delete_selection does is call
Mark Doliner <markdoliner@pidgin.im>
parents: 25888
diff changeset
4890 gtk_text_buffer_delete_selection(imhtml->text_buffer, TRUE, TRUE);
11750
63f951281392 [gaim-migrate @ 14041]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 11701
diff changeset
4891
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4892 mark = gtk_text_buffer_get_insert(imhtml->text_buffer);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4893
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4894 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark);
29288
56ad38f4d192 Explicitly mark user-interaction when inserting smiley.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29153
diff changeset
4895 gtk_text_buffer_begin_user_action(imhtml->text_buffer);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4896 gtk_imhtml_insert_smiley_at_iter(imhtml, sml, smiley, &iter);
29288
56ad38f4d192 Explicitly mark user-interaction when inserting smiley.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29153
diff changeset
4897 gtk_text_buffer_end_user_action(imhtml->text_buffer);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4898 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4899
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4900 /* TODO: I think this can be removed for GTK+ 3.0... */
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4901 #if 0
13552
1b9cad7ba558 [gaim-migrate @ 15929]
Fernando Herrera
parents: 13539
diff changeset
4902 static gboolean
1b9cad7ba558 [gaim-migrate @ 15929]
Fernando Herrera
parents: 13539
diff changeset
4903 image_expose(GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
1b9cad7ba558 [gaim-migrate @ 15929]
Fernando Herrera
parents: 13539
diff changeset
4904 {
1b9cad7ba558 [gaim-migrate @ 15929]
Fernando Herrera
parents: 13539
diff changeset
4905 GTK_WIDGET_CLASS(GTK_WIDGET_GET_CLASS(widget))->expose_event(widget, event);
1b9cad7ba558 [gaim-migrate @ 15929]
Fernando Herrera
parents: 13539
diff changeset
4906
1b9cad7ba558 [gaim-migrate @ 15929]
Fernando Herrera
parents: 13539
diff changeset
4907 return TRUE;
1b9cad7ba558 [gaim-migrate @ 15929]
Fernando Herrera
parents: 13539
diff changeset
4908 }
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4909 #endif
13552
1b9cad7ba558 [gaim-migrate @ 15929]
Fernando Herrera
parents: 13539
diff changeset
4910
16385
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4911 /* In case the smiley gets removed from the imhtml before it gets removed from the queue */
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
4912 static void animated_smiley_destroy_cb(GtkWidget *widget, GtkIMHtml *imhtml)
16385
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4913 {
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4914 GList *l = imhtml->animations->head;
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4915 while (l) {
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4916 GList *next = l->next;
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4917 if (l->data == widget) {
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4918 if (l == imhtml->animations->tail)
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4919 imhtml->animations->tail = imhtml->animations->tail->prev;
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4920 imhtml->animations->head = g_list_delete_link(imhtml->animations->head, l);
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4921 imhtml->num_animations--;
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4922 }
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4923 l = next;
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4924 }
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4925 }
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4926
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4927 void gtk_imhtml_insert_smiley_at_iter(GtkIMHtml *imhtml, const char *sml, char *smiley, GtkTextIter *iter)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
4928 {
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4929 GdkPixbuf *pixbuf = NULL;
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4930 GdkPixbufAnimation *annipixbuf = NULL;
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4931 GtkWidget *icon = NULL;
17009
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
4932 GtkTextChildAnchor *anchor = NULL;
29378
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
4933 char *unescaped;
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
4934 GtkIMHtmlSmiley *imhtml_smiley;
17009
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
4935 GtkWidget *ebox = NULL;
29378
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
4936 int numsmileys_thismsg, numsmileys_total;
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
4937
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
4938 /*
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
4939 * This GtkIMHtml has the maximum number of smileys allowed, so don't
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
4940 * add any more. We do this for performance reasons, because smileys
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
4941 * are apparently pretty inefficient. Hopefully we can remove this
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
4942 * restriction when we're using a better HTML widget.
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
4943 */
31192
57ce28c7314f gtkimhtml: Display "<3" instead of "&lt;3" after too many smileys in convo
Paul Aurich <darkrain42@pidgin.im>
parents: 30706
diff changeset
4944 unescaped = purple_unescape_html(smiley);
29378
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
4945 numsmileys_thismsg = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(imhtml), "gtkimhtml_numsmileys_thismsg"));
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
4946 if (numsmileys_thismsg >= 30) {
31192
57ce28c7314f gtkimhtml: Display "<3" instead of "&lt;3" after too many smileys in convo
Paul Aurich <darkrain42@pidgin.im>
parents: 30706
diff changeset
4947 gtk_text_buffer_insert(imhtml->text_buffer, iter, unescaped, -1);
57ce28c7314f gtkimhtml: Display "<3" instead of "&lt;3" after too many smileys in convo
Paul Aurich <darkrain42@pidgin.im>
parents: 30706
diff changeset
4948 g_free(unescaped);
29378
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
4949 return;
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
4950 }
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
4951 numsmileys_total = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(imhtml), "gtkimhtml_numsmileys_total"));
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
4952 if (numsmileys_total >= 300) {
31192
57ce28c7314f gtkimhtml: Display "<3" instead of "&lt;3" after too many smileys in convo
Paul Aurich <darkrain42@pidgin.im>
parents: 30706
diff changeset
4953 gtk_text_buffer_insert(imhtml->text_buffer, iter, unescaped, -1);
57ce28c7314f gtkimhtml: Display "<3" instead of "&lt;3" after too many smileys in convo
Paul Aurich <darkrain42@pidgin.im>
parents: 30706
diff changeset
4954 g_free(unescaped);
29378
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
4955 return;
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
4956 }
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
4957
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
4958 imhtml_smiley = gtk_imhtml_smiley_get(imhtml, sml, unescaped);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4959
10526
05b5c6d4090d [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
4960 if (imhtml->format_functions & GTK_IMHTML_SMILEY) {
29378
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
4961 annipixbuf = imhtml_smiley ? gtk_smiley_get_image(imhtml_smiley) : NULL;
10526
05b5c6d4090d [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
4962 if (annipixbuf) {
05b5c6d4090d [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
4963 if (gdk_pixbuf_animation_is_static_image(annipixbuf)) {
10522
d505522bcc93 [gaim-migrate @ 11838]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10504
diff changeset
4964 pixbuf = gdk_pixbuf_animation_get_static_image(annipixbuf);
10526
05b5c6d4090d [gaim-migrate @ 11843]
Tim Ringenbach <marv@pidgin.im>
parents: 10525
diff changeset
4965 if (pixbuf)
10522
d505522bcc93 [gaim-migrate @ 11838]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10504
diff changeset
4966 icon = gtk_image_new_from_pixbuf(pixbuf);
d505522bcc93 [gaim-migrate @ 11838]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10504
diff changeset
4967 } else {
d505522bcc93 [gaim-migrate @ 11838]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10504
diff changeset
4968 icon = gtk_image_new_from_animation(annipixbuf);
16385
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4969 if (imhtml->num_animations == 20) {
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4970 GtkImage *image = GTK_IMAGE(g_queue_pop_head(imhtml->animations));
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4971 GdkPixbufAnimation *anim = gtk_image_get_animation(image);
20638
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
4972 g_signal_handlers_disconnect_matched(G_OBJECT(image), G_SIGNAL_MATCH_FUNC,
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
4973 0, 0, NULL, G_CALLBACK(animated_smiley_destroy_cb), NULL);
16385
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4974 if (anim) {
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4975 GdkPixbuf *pb = gdk_pixbuf_animation_get_static_image(anim);
20638
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
4976 if (pb != NULL) {
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
4977 GdkPixbuf *copy = gdk_pixbuf_copy(pb);
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
4978 gtk_image_set_from_pixbuf(image, copy);
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
4979 g_object_unref(G_OBJECT(copy));
38507ef4007f Fix some crashes with animated smileys. Fixes #3179, #938, #3134, #2872, #1594
Daniel Atallah <datallah@pidgin.im>
parents: 20330
diff changeset
4980 }
16385
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4981 }
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4982 } else {
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4983 imhtml->num_animations++;
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4984 }
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4985 g_signal_connect(G_OBJECT(icon), "destroy", G_CALLBACK(animated_smiley_destroy_cb), imhtml);
aa5b9456e258 Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents: 16291
diff changeset
4986 g_queue_push_tail(imhtml->animations, icon);
10522
d505522bcc93 [gaim-migrate @ 11838]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10504
diff changeset
4987 }
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4988 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4989 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4990
17189
7d0cf54d0f32 Do not crash when trying to insert a smiley for a protocol not mentioned
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17136
diff changeset
4991 if (imhtml_smiley && imhtml_smiley->flags & GTK_IMHTML_SMILEY_CUSTOM) {
17009
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
4992 ebox = gtk_event_box_new();
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
4993 gtk_event_box_set_visible_window(GTK_EVENT_BOX(ebox), FALSE);
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
4994 gtk_widget_show(ebox);
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
4995 }
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
4996
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
4997 if (icon) {
8890
0a37b4a8ff32 [gaim-migrate @ 9659]
Kevin Stange <kstange@pidgin.im>
parents: 8881
diff changeset
4998 anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter);
29371
990c60037f70 Minor cleanup
Mark Doliner <markdoliner@pidgin.im>
parents: 29309
diff changeset
4999 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_plaintext", g_strdup(unescaped), g_free);
990c60037f70 Minor cleanup
Mark Doliner <markdoliner@pidgin.im>
parents: 29309
diff changeset
5000 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_tiptext", g_strdup(unescaped), g_free);
8890
0a37b4a8ff32 [gaim-migrate @ 9659]
Kevin Stange <kstange@pidgin.im>
parents: 8881
diff changeset
5001 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_htmltext", g_strdup(smiley), g_free);
0a37b4a8ff32 [gaim-migrate @ 9659]
Kevin Stange <kstange@pidgin.im>
parents: 8881
diff changeset
5002
13552
1b9cad7ba558 [gaim-migrate @ 15929]
Fernando Herrera
parents: 13539
diff changeset
5003 /* This catches the expose events generated by animated
1b9cad7ba558 [gaim-migrate @ 15929]
Fernando Herrera
parents: 13539
diff changeset
5004 * images, and ensures that they are handled by the image
1b9cad7ba558 [gaim-migrate @ 15929]
Fernando Herrera
parents: 13539
diff changeset
5005 * itself, without propagating to the textview and causing
1b9cad7ba558 [gaim-migrate @ 15929]
Fernando Herrera
parents: 13539
diff changeset
5006 * a complete refresh */
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5007 /* TODO: I think this should be removed for GTK+ 3.0?
13552
1b9cad7ba558 [gaim-migrate @ 15929]
Fernando Herrera
parents: 13539
diff changeset
5008 g_signal_connect(G_OBJECT(icon), "expose-event", G_CALLBACK(image_expose), NULL);
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5009 */
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5010
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5011 gtk_widget_show(icon);
17009
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
5012 if (ebox)
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
5013 gtk_container_add(GTK_CONTAINER(ebox), icon);
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
5014 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), ebox ? ebox : icon, anchor);
29378
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
5015
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
5016 g_object_set_data(G_OBJECT(imhtml), "gtkimhtml_numsmileys_thismsg", GINT_TO_POINTER(numsmileys_thismsg + 1));
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
5017 g_object_set_data(G_OBJECT(imhtml), "gtkimhtml_numsmileys_total", GINT_TO_POINTER(numsmileys_total + 1));
11525
1d06283bdcc9 [gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents: 11485
diff changeset
5018 } else if (imhtml_smiley != NULL && (imhtml->format_functions & GTK_IMHTML_SMILEY)) {
1d06283bdcc9 [gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents: 11485
diff changeset
5019 anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter);
23398
4de581ccaf1e Do not try to update received custom smileys in a deleted child anchor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23377
diff changeset
5020 imhtml_smiley->anchors = g_slist_append(imhtml_smiley->anchors, g_object_ref(anchor));
17009
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
5021 if (ebox) {
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
5022 GtkWidget *img = gtk_image_new_from_stock(GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_MENU);
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
5023 gtk_container_add(GTK_CONTAINER(ebox), img);
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
5024 gtk_widget_show(img);
29371
990c60037f70 Minor cleanup
Mark Doliner <markdoliner@pidgin.im>
parents: 29309
diff changeset
5025 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_plaintext", g_strdup(unescaped), g_free);
990c60037f70 Minor cleanup
Mark Doliner <markdoliner@pidgin.im>
parents: 29309
diff changeset
5026 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_tiptext", g_strdup(unescaped), g_free);
27173
e601bcf2e1a6 We want to see what the missing custom smiley stands for.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27125
diff changeset
5027 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_htmltext", g_strdup(smiley), g_free);
17009
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
5028 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), ebox, anchor);
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
5029 }
29378
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
5030
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
5031 g_object_set_data(G_OBJECT(imhtml), "gtkimhtml_numsmileys_thismsg", GINT_TO_POINTER(numsmileys_thismsg + 1));
a783b23a05da Fix CVE-2010-0423, a denial of service attack due to the parsing
Mark Doliner <markdoliner@pidgin.im>
parents: 29371
diff changeset
5032 g_object_set_data(G_OBJECT(imhtml), "gtkimhtml_numsmileys_total", GINT_TO_POINTER(numsmileys_total + 1));
8890
0a37b4a8ff32 [gaim-migrate @ 9659]
Kevin Stange <kstange@pidgin.im>
parents: 8881
diff changeset
5033 } else {
31192
57ce28c7314f gtkimhtml: Display "<3" instead of "&lt;3" after too many smileys in convo
Paul Aurich <darkrain42@pidgin.im>
parents: 30706
diff changeset
5034 gtk_text_buffer_insert(imhtml->text_buffer, iter, unescaped, -1);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5035 }
8890
0a37b4a8ff32 [gaim-migrate @ 9659]
Kevin Stange <kstange@pidgin.im>
parents: 8881
diff changeset
5036
17009
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
5037 if (ebox) {
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
5038 g_signal_connect(G_OBJECT(ebox), "event", G_CALLBACK(gtk_imhtml_smiley_clicked), imhtml_smiley);
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
5039 }
2cc9edf33feb Allow saving custom smileys by right-clicking on them. And use the custom smileys only on the received messages, not for the system/etc. messages.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16385
diff changeset
5040
8890
0a37b4a8ff32 [gaim-migrate @ 9659]
Kevin Stange <kstange@pidgin.im>
parents: 8881
diff changeset
5041 g_free(unescaped);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5042 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5043
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5044 void gtk_imhtml_insert_image_at_iter(GtkIMHtml *imhtml, int id, GtkTextIter *iter)
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5045 {
18151
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
5046 GdkPixbufAnimation *anim = NULL;
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5047 const char *filename = NULL;
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5048 gpointer image;
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5049 GdkRectangle rect;
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5050 GtkIMHtmlScalable *scalable = NULL;
11224
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
5051 struct scalable_data *sd;
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5052 int minus;
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5053
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5054 if (!imhtml->funcs || !imhtml->funcs->image_get ||
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5055 !imhtml->funcs->image_get_size || !imhtml->funcs->image_get_data ||
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5056 !imhtml->funcs->image_get_filename || !imhtml->funcs->image_ref ||
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5057 !imhtml->funcs->image_unref)
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5058 return;
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5059
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5060 image = imhtml->funcs->image_get(id);
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5061
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5062 if (image) {
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5063 gpointer data;
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5064 size_t len;
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5065
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5066 data = imhtml->funcs->image_get_data(image);
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5067 len = imhtml->funcs->image_get_size(image);
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5068
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5069 if (data && len) {
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5070 GdkPixbufLoader *loader = gdk_pixbuf_loader_new();
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5071 gdk_pixbuf_loader_write(loader, data, len, NULL);
12230
2f327bccf63b [gaim-migrate @ 14532]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 12229
diff changeset
5072 gdk_pixbuf_loader_close(loader, NULL);
18151
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
5073 anim = gdk_pixbuf_loader_get_animation(loader);
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
5074 if (anim)
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
5075 g_object_ref(G_OBJECT(anim));
9337
4bd369a6e4dc [gaim-migrate @ 10145]
Tim Ringenbach <marv@pidgin.im>
parents: 9335
diff changeset
5076 g_object_unref(G_OBJECT(loader));
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5077 }
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5078
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5079 }
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5080
18151
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
5081 if (anim) {
11299
06bb44ed0cf3 [gaim-migrate @ 13499]
Richard Laager <rlaager@pidgin.im>
parents: 11276
diff changeset
5082 struct im_image_data *t = g_new(struct im_image_data, 1);
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5083 filename = imhtml->funcs->image_get_filename(image);
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5084 imhtml->funcs->image_ref(id);
11224
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
5085 t->id = id;
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
5086 t->mark = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, iter, TRUE);
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
5087 imhtml->im_images = g_slist_prepend(imhtml->im_images, t);
18151
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
5088 scalable = gtk_imhtml_animation_new(anim, filename, id);
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
5089 g_object_unref(G_OBJECT(anim));
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5090 } else {
18151
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
5091 GdkPixbuf *pixbuf;
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5092 pixbuf = gtk_widget_render_icon(GTK_WIDGET(imhtml), GTK_STOCK_MISSING_IMAGE,
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5093 GTK_ICON_SIZE_BUTTON, "gtkimhtml-missing-image");
18151
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
5094 scalable = gtk_imhtml_image_new(pixbuf, filename, id);
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
5095 g_object_unref(G_OBJECT(pixbuf));
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5096 }
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5097
11224
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
5098 sd = g_new(struct scalable_data, 1);
18151
97fd60f47229 When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents: 18119
diff changeset
5099 sd->scalable = scalable;
11233
28c0f184a2d4 [gaim-migrate @ 13373]
Daniel Atallah <datallah@pidgin.im>
parents: 11224
diff changeset
5100 sd->mark = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, iter, TRUE);
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5101 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect);
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5102 scalable->add_to(scalable, imhtml, iter);
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5103 minus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(imhtml)) +
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5104 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(imhtml));
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5105 scalable->scale(scalable, rect.width - minus, rect.height);
11224
04c1712bb953 [gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents: 11143
diff changeset
5106 imhtml->scalables = g_list_append(imhtml->scalables, sd);
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5107 }
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5108
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5109 static const gchar *tag_to_html_start(GtkTextTag *tag)
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5110 {
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5111 static gchar buf[1024];
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5112 gchar *name = NULL;
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5113
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5114 g_return_val_if_fail(name != NULL, "");
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5115 g_object_get(G_OBJECT(tag), "name", &name, NULL);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5116
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5117 if (strcmp(name, "BOLD") == 0) {
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5118 g_free(name);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5119 return "<b>";
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5120 } else if (strcmp(name, "ITALICS") == 0) {
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5121 g_free(name);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5122 return "<i>";
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5123 } else if (strcmp(name, "UNDERLINE") == 0) {
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5124 g_free(name);
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5125 return "<u>";
9924
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
5126 } else if (strcmp(name, "STRIKE") == 0) {
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5127 g_free(name);
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5128 return "<s>";
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5129 } else if (strncmp(name, "LINK ", 5) == 0) {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5130 char *tmp = g_object_get_data(G_OBJECT(tag), "link_url");
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
5131
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5132 g_free(name);
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5133
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5134 if (tmp) {
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5135 g_snprintf(buf, sizeof(buf), "<a href=\"%s\">", tmp);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5136 buf[sizeof(buf)-1] = '\0';
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5137 return buf;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5138 } else {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5139 return "";
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5140 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5141 } else if (strncmp(name, "FORECOLOR ", 10) == 0) {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5142 g_snprintf(buf, sizeof(buf), "<font color=\"%s\">", &name[10]);
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
5143
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5144 g_free(name);
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5145
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5146 return buf;
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5147 } else if (strncmp(name, "BACKCOLOR ", 10) == 0) {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5148 g_snprintf(buf, sizeof(buf), "<font back=\"%s\">", &name[10]);
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5149 g_free(name);
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5150
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5151 return buf;
10776
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
5152 } else if (strncmp(name, "BACKGROUND ", 10) == 0) {
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
5153 g_snprintf(buf, sizeof(buf), "<body bgcolor=\"%s\">", &name[11]);
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5154 g_free(name);
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5155
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5156 return buf;
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5157 } else if (strncmp(name, "FONT FACE ", 10) == 0) {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5158 g_snprintf(buf, sizeof(buf), "<font face=\"%s\">", &name[10]);
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5159 g_free(name);
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5160
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5161 return buf;
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5162 } else if (strncmp(name, "FONT SIZE ", 10) == 0) {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5163 g_snprintf(buf, sizeof(buf), "<font size=\"%s\">", &name[10]);
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5164 g_free(name);
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5165
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5166 return buf;
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5167 } else {
23308
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5168 char *str = buf;
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5169 gboolean isset;
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5170 int ivalue = 0;
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5171 GdkColor *color = NULL;
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5172 GObject *obj = G_OBJECT(tag);
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5173 gboolean empty = TRUE;
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5174
23310
e34473be13db Get rid of the boldness of the bold timestamps.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23308
diff changeset
5175 str += g_snprintf(str, sizeof(buf) - (str - buf), "<span style='");
23308
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5176
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5177 /* Weight */
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5178 g_object_get(obj, "weight-set", &isset, "weight", &ivalue, NULL);
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5179 if (isset) {
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5180 const char *weight = "";
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5181 if (ivalue >= PANGO_WEIGHT_ULTRABOLD)
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5182 weight = "bolder";
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5183 else if (ivalue >= PANGO_WEIGHT_BOLD)
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5184 weight = "bold";
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5185 else if (ivalue >= PANGO_WEIGHT_NORMAL)
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5186 weight = "normal";
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5187 else
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5188 weight = "lighter";
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5189
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5190 str += g_snprintf(str, sizeof(buf) - (str - buf), "font-weight: %s;", weight);
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5191 empty = FALSE;
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5192 }
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5193
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5194 /* Foreground color */
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5195 g_object_get(obj, "foreground-set", &isset, "foreground-gdk", &color, NULL);
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5196 if (isset && color) {
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5197 str += g_snprintf(str, sizeof(buf) - (str - buf),
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5198 "color: #%02x%02x%02x;",
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5199 color->red >> 8, color->green >> 8, color->blue >> 8);
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5200 empty = FALSE;
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5201 }
23466
7380df2e12f1 Patch from Andrew Gaul that fixes another leak:
Ka-Hing Cheung <khc@pidgin.im>
parents: 23465
diff changeset
5202 gdk_color_free(color);
23308
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5203
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5204 /* Background color */
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5205 g_object_get(obj, "background-set", &isset, "background-gdk", &color, NULL);
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5206 if (isset && color) {
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5207 str += g_snprintf(str, sizeof(buf) - (str - buf),
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5208 "background: #%02x%02x%02x;",
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5209 color->red >> 8, color->green >> 8, color->blue >> 8);
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5210 empty = FALSE;
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5211 }
23466
7380df2e12f1 Patch from Andrew Gaul that fixes another leak:
Ka-Hing Cheung <khc@pidgin.im>
parents: 23465
diff changeset
5212 gdk_color_free(color);
23308
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5213
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5214 /* Underline */
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5215 g_object_get(obj, "underline-set", &isset, "underline", &ivalue, NULL);
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5216 if (isset) {
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5217 switch (ivalue) {
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5218 case PANGO_UNDERLINE_NONE:
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5219 case PANGO_UNDERLINE_ERROR:
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5220 break;
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5221 default:
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5222 str += g_snprintf(str, sizeof(buf) - (str - buf), "text-decoration: underline;");
23365
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5223 empty = FALSE;
23308
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5224 }
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5225 }
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5226
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5227 g_snprintf(str, sizeof(buf) - (str - buf), "'>");
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5228 g_free(name);
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5229
23308
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5230 return (empty ? "" : buf);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5231 }
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5232 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5233
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5234 static const gchar *tag_to_html_end(GtkTextTag *tag)
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5235 {
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
5236 gchar *name;
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
5237
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5238 g_return_val_if_fail(name != NULL, "");
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5239 g_object_get(G_OBJECT(tag), "name", &name, NULL);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5240
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5241 if (strcmp(name, "BOLD") == 0) {
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5242 g_free(name);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5243 return "</b>";
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5244 } else if (strcmp(name, "ITALICS") == 0) {
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5245 g_free(name);
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5246 return "</i>";
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5247 } else if (strcmp(name, "UNDERLINE") == 0) {
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5248 g_free(name);
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5249 return "</u>";
9924
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
5250 } else if (strcmp(name, "STRIKE") == 0) {
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5251 g_free(name);
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5252 return "</s>";
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5253 } else if (strncmp(name, "LINK ", 5) == 0) {
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5254 g_free(name);
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5255 return "</a>";
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5256 } else if (strncmp(name, "FORECOLOR ", 10) == 0) {
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5257 g_free(name);
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5258 return "</font>";
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5259 } else if (strncmp(name, "BACKCOLOR ", 10) == 0) {
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5260 g_free(name);
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5261 return "</font>";
10776
b474d64f94ac [gaim-migrate @ 12387]
Tim Ringenbach <marv@pidgin.im>
parents: 10770
diff changeset
5262 } else if (strncmp(name, "BACKGROUND ", 10) == 0) {
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5263 g_free(name);
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5264 return "</body>";
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5265 } else if (strncmp(name, "FONT FACE ", 10) == 0) {
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5266 g_free(name);
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5267 return "</font>";
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5268 } else if (strncmp(name, "FONT SIZE ", 10) == 0) {
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5269 g_free(name);
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5270 return "</font>";
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5271 } else {
23308
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5272 const char *props[] = {"weight-set", "foreground-set", "background-set",
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5273 "size-set", "underline-set", NULL};
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5274 int i;
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5275 for (i = 0; props[i]; i++) {
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5276 gboolean set = FALSE;
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5277 g_object_get(G_OBJECT(tag), props[i], &set, NULL);
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5278 if (set)
23310
e34473be13db Get rid of the boldness of the bold timestamps.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23308
diff changeset
5279 return "</span>";
23308
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5280 }
ccc2815ee9a1 Fix exporting proper HTML for tags.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23304
diff changeset
5281
32413
00ad036bdf3d Fix some indenting.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32412
diff changeset
5282 g_free(name);
32394
f883709bdba4 compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents: 31207
diff changeset
5283
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5284 return "";
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5285 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5286 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5287
23365
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5288 typedef struct {
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5289 GtkTextTag *tag;
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5290 char *end;
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5291 char *start;
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5292 } PidginTextTagData;
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5293
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5294 static PidginTextTagData *text_tag_data_new(GtkTextTag *tag)
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5295 {
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5296 const char *start, *end;
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5297 PidginTextTagData *ret = NULL;
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5298
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5299 start = tag_to_html_start(tag);
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5300 if (!start || !*start)
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5301 return NULL;
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5302 end = tag_to_html_end(tag);
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5303 if (!end || !*end)
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5304 return NULL;
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5305
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5306 ret = g_new0(PidginTextTagData, 1);
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5307 ret->start = g_strdup(start);
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5308 ret->end = g_strdup(end);
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5309 ret->tag = tag;
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5310 return ret;
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5311 }
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5312
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5313 static void text_tag_data_destroy(PidginTextTagData *data)
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5314 {
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5315 g_free(data->start);
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5316 g_free(data->end);
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5317 g_free(data);
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5318 }
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5319
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5320 static gboolean tag_ends_here(GtkTextTag *tag, GtkTextIter *iter, GtkTextIter *niter)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5321 {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5322 return ((gtk_text_iter_has_tag(iter, GTK_TEXT_TAG(tag)) &&
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5323 !gtk_text_iter_has_tag(niter, GTK_TEXT_TAG(tag))) ||
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5324 gtk_text_iter_is_end(niter));
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5325 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5326
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5327 /* Basic notion here: traverse through the text buffer one-by-one, non-character elements, such
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5328 * as smileys and IM images are represented by the Unicode "unknown" character. Handle them. Else
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5329 * check for tags that are toggled on, insert their html form, and push them on the queue. Then insert
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5330 * the actual text. Then check for tags that are toggled off and insert them, after checking the queue.
8735
01248ea222d3 [gaim-migrate @ 9490]
Jonathan Champ <royanee@users.sourceforge.net>
parents: 8729
diff changeset
5331 * Finally, replace <, >, &, and " with their HTML equivalent.
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5332 */
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5333 char *gtk_imhtml_get_markup_range(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end)
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5334 {
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5335 gunichar c;
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
5336 GtkTextIter iter, next_iter, non_neutral_iter;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
5337 gboolean is_rtl_message = FALSE;
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5338 GString *str = g_string_new("");
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5339 GSList *tags, *sl;
23365
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5340 GQueue *q;
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5341 GtkTextTag *tag;
23365
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5342 PidginTextTagData *tagdata;
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5343
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5344 q = g_queue_new();
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5345
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5346 gtk_text_iter_order(start, end);
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
5347 non_neutral_iter = next_iter = iter = *start;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
5348 gtk_text_iter_forward_char(&next_iter);
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
5349
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
5350 /* Bi-directional text support */
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
5351 /* Get to the first non-neutral character */
16291
acbfc9276da1 Fix for using Pango < 1.4, will not have complete RTL support with older
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 16254
diff changeset
5352 #ifdef HAVE_PANGO14
16144
4e022531d1c9 Patch cleanups:
Richard Laager <rlaager@pidgin.im>
parents: 16143
diff changeset
5353 while ((PANGO_DIRECTION_NEUTRAL == pango_unichar_direction(gtk_text_iter_get_char(&non_neutral_iter)))
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
5354 && gtk_text_iter_forward_char(&non_neutral_iter));
16144
4e022531d1c9 Patch cleanups:
Richard Laager <rlaager@pidgin.im>
parents: 16143
diff changeset
5355 if (PANGO_DIRECTION_RTL == pango_unichar_direction(gtk_text_iter_get_char(&non_neutral_iter))) {
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
5356 is_rtl_message = TRUE;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
5357 g_string_append(str, "<SPAN style=\"direction:rtl;text-align:right;\">");
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
5358 }
16291
acbfc9276da1 Fix for using Pango < 1.4, will not have complete RTL support with older
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 16254
diff changeset
5359 #endif
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5360
9071
a3b12b59a58b [gaim-migrate @ 9847]
Daniel Atallah <datallah@pidgin.im>
parents: 9037
diff changeset
5361 /* First add the tags that are already in progress (we don't care about non-printing tags)*/
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5362 tags = gtk_text_iter_get_tags(start);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5363
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5364 for (sl = tags; sl; sl = sl->next) {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5365 tag = sl->data;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5366 if (!gtk_text_iter_toggles_tag(start, GTK_TEXT_TAG(tag))) {
23365
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5367 PidginTextTagData *data = text_tag_data_new(tag);
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5368 if (data) {
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5369 g_string_append(str, data->start);
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5370 g_queue_push_tail(q, data);
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5371 }
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5372 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5373 }
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5374 g_slist_free(tags);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5375
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5376 while ((c = gtk_text_iter_get_char(&iter)) != 0 && !gtk_text_iter_equal(&iter, end)) {
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5377
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5378 tags = gtk_text_iter_get_tags(&iter);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5379
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5380 for (sl = tags; sl; sl = sl->next) {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5381 tag = sl->data;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5382 if (gtk_text_iter_begins_tag(&iter, GTK_TEXT_TAG(tag))) {
23365
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5383 PidginTextTagData *data = text_tag_data_new(tag);
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5384 if (data) {
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5385 g_string_append(str, data->start);
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5386 g_queue_push_tail(q, data);
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5387 }
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5388 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5389 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5390
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5391 if (c == 0xFFFC) {
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5392 GtkTextChildAnchor* anchor = gtk_text_iter_get_child_anchor(&iter);
9071
a3b12b59a58b [gaim-migrate @ 9847]
Daniel Atallah <datallah@pidgin.im>
parents: 9037
diff changeset
5393 if (anchor) {
a3b12b59a58b [gaim-migrate @ 9847]
Daniel Atallah <datallah@pidgin.im>
parents: 9037
diff changeset
5394 char *text = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_htmltext");
a3b12b59a58b [gaim-migrate @ 9847]
Daniel Atallah <datallah@pidgin.im>
parents: 9037
diff changeset
5395 if (text)
a3b12b59a58b [gaim-migrate @ 9847]
Daniel Atallah <datallah@pidgin.im>
parents: 9037
diff changeset
5396 str = g_string_append(str, text);
a3b12b59a58b [gaim-migrate @ 9847]
Daniel Atallah <datallah@pidgin.im>
parents: 9037
diff changeset
5397 }
11572
3aaac95fa1ec [gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents: 11525
diff changeset
5398 } else if (c == '<') {
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5399 str = g_string_append(str, "&lt;");
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5400 } else if (c == '>') {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5401 str = g_string_append(str, "&gt;");
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5402 } else if (c == '&') {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5403 str = g_string_append(str, "&amp;");
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5404 } else if (c == '"') {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5405 str = g_string_append(str, "&quot;");
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5406 } else if (c == '\n') {
19746
4537d921dab4 disapproval of revision '10d0834255f911ca2359c74b430025155af2b22e'
Kevin Stange <kstange@pidgin.im>
parents: 19745
diff changeset
5407 str = g_string_append(str, "<br>");
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5408 } else {
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5409 str = g_string_append_unichar(str, c);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5410 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5411
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5412 tags = g_slist_reverse(tags);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5413 for (sl = tags; sl; sl = sl->next) {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5414 tag = sl->data;
9071
a3b12b59a58b [gaim-migrate @ 9847]
Daniel Atallah <datallah@pidgin.im>
parents: 9037
diff changeset
5415 /** don't worry about non-printing tags ending */
23365
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5416 if (tag_ends_here(tag, &iter, &next_iter) &&
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5417 strlen(tag_to_html_end(tag)) > 0 &&
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5418 strlen(tag_to_html_start(tag)) > 0) {
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5419
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5420 PidginTextTagData *tmp;
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5421 GQueue *r = g_queue_new();
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5422
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5423 while ((tmp = g_queue_pop_tail(q)) && tmp->tag != tag) {
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5424 g_string_append(str, tmp->end);
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5425 if (!tag_ends_here(tmp->tag, &iter, &next_iter))
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5426 g_queue_push_tail(r, tmp);
23365
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5427 else
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5428 text_tag_data_destroy(tmp);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5429 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5430
25470
b1777c3ab2bb Prevent a crash that can occur while copying the contents of the Debug Window. This ends up masking mismatched tags in the imhtml output, but that is
Daniel Atallah <datallah@pidgin.im>
parents: 25299
diff changeset
5431 if (tmp != NULL) {
23365
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5432 g_string_append(str, tmp->end);
23465
e20729245830 Patch from Andrew Gaul that fixes a leak:
Ka-Hing Cheung <khc@pidgin.im>
parents: 23398
diff changeset
5433 text_tag_data_destroy(tmp);
e20729245830 Patch from Andrew Gaul that fixes a leak:
Ka-Hing Cheung <khc@pidgin.im>
parents: 23398
diff changeset
5434 }
25470
b1777c3ab2bb Prevent a crash that can occur while copying the contents of the Debug Window. This ends up masking mismatched tags in the imhtml output, but that is
Daniel Atallah <datallah@pidgin.im>
parents: 25299
diff changeset
5435 #if 0 /* This can't be allowed to happen because it causes the iters to be invalidated in the debug window imhtml during text copying */
b1777c3ab2bb Prevent a crash that can occur while copying the contents of the Debug Window. This ends up masking mismatched tags in the imhtml output, but that is
Daniel Atallah <datallah@pidgin.im>
parents: 25299
diff changeset
5436 else
b1777c3ab2bb Prevent a crash that can occur while copying the contents of the Debug Window. This ends up masking mismatched tags in the imhtml output, but that is
Daniel Atallah <datallah@pidgin.im>
parents: 25299
diff changeset
5437 purple_debug_warning("gtkimhtml", "empty queue, more closing tags than open tags!\n");
b1777c3ab2bb Prevent a crash that can occur while copying the contents of the Debug Window. This ends up masking mismatched tags in the imhtml output, but that is
Daniel Atallah <datallah@pidgin.im>
parents: 25299
diff changeset
5438 #endif
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5439
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5440 while ((tmp = g_queue_pop_head(r))) {
23365
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5441 g_string_append(str, tmp->start);
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5442 g_queue_push_tail(q, tmp);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5443 }
23365
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5444 g_queue_free(r);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5445 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5446 }
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5447
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5448 g_slist_free(tags);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5449 gtk_text_iter_forward_char(&iter);
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
5450 gtk_text_iter_forward_char(&next_iter);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5451 }
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5452
23365
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5453 while ((tagdata = g_queue_pop_tail(q))) {
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5454 g_string_append(str, tagdata->end);
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5455 text_tag_data_destroy(tagdata);
fc1df3495580 Fix the linkification. Also, remember the html-codes for a tag instead of
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23332
diff changeset
5456 }
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5457
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
5458 /* Bi-directional text support - close tags */
16144
4e022531d1c9 Patch cleanups:
Richard Laager <rlaager@pidgin.im>
parents: 16143
diff changeset
5459 if (is_rtl_message)
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
5460 g_string_append(str, "</SPAN>");
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15931
diff changeset
5461
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5462 g_queue_free(q);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5463 return g_string_free(str, FALSE);
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5464 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5465
8698
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
5466 void gtk_imhtml_close_tags(GtkIMHtml *imhtml, GtkTextIter *iter)
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5467 {
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5468 if (imhtml->edit.bold)
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5469 gtk_imhtml_toggle_bold(imhtml);
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5470
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5471 if (imhtml->edit.italic)
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5472 gtk_imhtml_toggle_italic(imhtml);
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5473
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5474 if (imhtml->edit.underline)
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5475 gtk_imhtml_toggle_underline(imhtml);
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5476
9924
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
5477 if (imhtml->edit.strike)
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
5478 gtk_imhtml_toggle_strike(imhtml);
55cc2ac0bd3f [gaim-migrate @ 10816]
Tim Ringenbach <marv@pidgin.im>
parents: 9815
diff changeset
5479
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5480 if (imhtml->edit.forecolor)
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5481 gtk_imhtml_toggle_forecolor(imhtml, NULL);
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5482
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5483 if (imhtml->edit.backcolor)
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5484 gtk_imhtml_toggle_backcolor(imhtml, NULL);
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5485
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5486 if (imhtml->edit.fontface)
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5487 gtk_imhtml_toggle_fontface(imhtml, NULL);
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5488
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5489 imhtml->edit.fontsize = 0;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5490
8719
1d1a4e11b4ab [gaim-migrate @ 9474]
Tim Ringenbach <marv@pidgin.im>
parents: 8707
diff changeset
5491 if (imhtml->edit.link)
1d1a4e11b4ab [gaim-migrate @ 9474]
Tim Ringenbach <marv@pidgin.im>
parents: 8707
diff changeset
5492 gtk_imhtml_toggle_link(imhtml, NULL);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5493 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5494
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5495 char *gtk_imhtml_get_markup(GtkIMHtml *imhtml)
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5496 {
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5497 GtkTextIter start, end;
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5498
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5499 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start);
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5500 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end);
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5501 return gtk_imhtml_get_markup_range(imhtml, &start, &end);
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5502 }
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5503
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5504 char **gtk_imhtml_get_markup_lines(GtkIMHtml *imhtml)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5505 {
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5506 int i, j, lines;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5507 GtkTextIter start, end;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5508 char **ret;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5509
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5510 lines = gtk_text_buffer_get_line_count(imhtml->text_buffer);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5511 ret = g_new0(char *, lines + 1);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5512 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5513 end = start;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5514 gtk_text_iter_forward_to_line_end(&end);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5515
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5516 for (i = 0, j = 0; i < lines; i++) {
9612
89f5a9900fdd [gaim-migrate @ 10455]
Tim Ringenbach <marv@pidgin.im>
parents: 9599
diff changeset
5517 if (gtk_text_iter_get_char(&start) != '\n') {
89f5a9900fdd [gaim-migrate @ 10455]
Tim Ringenbach <marv@pidgin.im>
parents: 9599
diff changeset
5518 ret[j] = gtk_imhtml_get_markup_range(imhtml, &start, &end);
89f5a9900fdd [gaim-migrate @ 10455]
Tim Ringenbach <marv@pidgin.im>
parents: 9599
diff changeset
5519 if (ret[j] != NULL)
89f5a9900fdd [gaim-migrate @ 10455]
Tim Ringenbach <marv@pidgin.im>
parents: 9599
diff changeset
5520 j++;
89f5a9900fdd [gaim-migrate @ 10455]
Tim Ringenbach <marv@pidgin.im>
parents: 9599
diff changeset
5521 }
89f5a9900fdd [gaim-migrate @ 10455]
Tim Ringenbach <marv@pidgin.im>
parents: 9599
diff changeset
5522
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5523 gtk_text_iter_forward_line(&start);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5524 end = start;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5525 gtk_text_iter_forward_to_line_end(&end);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5526 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5527
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5528 return ret;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5529 }
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5530
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5531 char *gtk_imhtml_get_text(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *stop)
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5532 {
8519
13be07662047 [gaim-migrate @ 9258]
Gary Kramlich <grim@pidgin.im>
parents: 8516
diff changeset
5533 GString *str = g_string_new("");
13be07662047 [gaim-migrate @ 9258]
Gary Kramlich <grim@pidgin.im>
parents: 8516
diff changeset
5534 GtkTextIter iter, end;
13be07662047 [gaim-migrate @ 9258]
Gary Kramlich <grim@pidgin.im>
parents: 8516
diff changeset
5535 gunichar c;
13be07662047 [gaim-migrate @ 9258]
Gary Kramlich <grim@pidgin.im>
parents: 8516
diff changeset
5536
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5537 if (start == NULL)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5538 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5539 else
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5540 iter = *start;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5541
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5542 if (stop == NULL)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5543 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5544 else
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5545 end = *stop;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5546
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5547 gtk_text_iter_order(&iter, &end);
8519
13be07662047 [gaim-migrate @ 9258]
Gary Kramlich <grim@pidgin.im>
parents: 8516
diff changeset
5548
13be07662047 [gaim-migrate @ 9258]
Gary Kramlich <grim@pidgin.im>
parents: 8516
diff changeset
5549 while ((c = gtk_text_iter_get_char(&iter)) != 0 && !gtk_text_iter_equal(&iter, &end)) {
13be07662047 [gaim-migrate @ 9258]
Gary Kramlich <grim@pidgin.im>
parents: 8516
diff changeset
5550 if (c == 0xFFFC) {
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5551 GtkTextChildAnchor* anchor;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5552 char *text = NULL;
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5553
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5554 anchor = gtk_text_iter_get_child_anchor(&iter);
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5555 if (anchor)
8698
47d7bcc95e40 [gaim-migrate @ 9451]
Tim Ringenbach <marv@pidgin.im>
parents: 8693
diff changeset
5556 text = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_plaintext");
8677
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5557 if (text)
18b494207322 [gaim-migrate @ 9430]
Tim Ringenbach <marv@pidgin.im>
parents: 8654
diff changeset
5558 str = g_string_append(str, text);
8519
13be07662047 [gaim-migrate @ 9258]
Gary Kramlich <grim@pidgin.im>
parents: 8516
diff changeset
5559 } else {
13be07662047 [gaim-migrate @ 9258]
Gary Kramlich <grim@pidgin.im>
parents: 8516
diff changeset
5560 g_string_append_unichar(str, c);
13be07662047 [gaim-migrate @ 9258]
Gary Kramlich <grim@pidgin.im>
parents: 8516
diff changeset
5561 }
13be07662047 [gaim-migrate @ 9258]
Gary Kramlich <grim@pidgin.im>
parents: 8516
diff changeset
5562 gtk_text_iter_forward_char(&iter);
13be07662047 [gaim-migrate @ 9258]
Gary Kramlich <grim@pidgin.im>
parents: 8516
diff changeset
5563 }
13be07662047 [gaim-migrate @ 9258]
Gary Kramlich <grim@pidgin.im>
parents: 8516
diff changeset
5564
13be07662047 [gaim-migrate @ 9258]
Gary Kramlich <grim@pidgin.im>
parents: 8516
diff changeset
5565 return g_string_free(str, FALSE);
8061
a765ea99b49f [gaim-migrate @ 8749]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
5566 }
8962
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5567
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5568 void gtk_imhtml_set_funcs(GtkIMHtml *imhtml, GtkIMHtmlFuncs *f)
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5569 {
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5570 g_return_if_fail(imhtml != NULL);
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5571 imhtml->funcs = f;
5cd12e525d95 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8957
diff changeset
5572 }
17388
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5573
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5574 void gtk_imhtml_setup_entry(GtkIMHtml *imhtml, PurpleConnectionFlags flags)
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5575 {
18240
0a7d2fde749b Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 18185
diff changeset
5576 GtkIMHtmlButtons buttons;
0a7d2fde749b Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 18185
diff changeset
5577
17388
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5578 if (flags & PURPLE_CONNECTION_HTML) {
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5579 char color[8];
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5580 GdkColor fg_color, bg_color;
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5581
18240
0a7d2fde749b Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 18185
diff changeset
5582 buttons = GTK_IMHTML_ALL;
0a7d2fde749b Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 18185
diff changeset
5583
0a7d2fde749b Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 18185
diff changeset
5584 if (flags & PURPLE_CONNECTION_NO_BGCOLOR)
0a7d2fde749b Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 18185
diff changeset
5585 buttons &= ~GTK_IMHTML_BACKCOLOR;
0a7d2fde749b Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 18185
diff changeset
5586 if (flags & PURPLE_CONNECTION_NO_FONTSIZE)
0a7d2fde749b Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 18185
diff changeset
5587 {
0a7d2fde749b Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 18185
diff changeset
5588 buttons &= ~GTK_IMHTML_GROW;
0a7d2fde749b Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 18185
diff changeset
5589 buttons &= ~GTK_IMHTML_SHRINK;
0a7d2fde749b Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 18185
diff changeset
5590 }
0a7d2fde749b Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 18185
diff changeset
5591 if (flags & PURPLE_CONNECTION_NO_URLDESC)
0a7d2fde749b Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 18185
diff changeset
5592 buttons &= ~GTK_IMHTML_LINKDESC;
0a7d2fde749b Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 18185
diff changeset
5593
17388
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5594 gtk_imhtml_set_format_functions(imhtml, GTK_IMHTML_ALL);
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5595 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_bold") != imhtml->edit.bold)
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5596 gtk_imhtml_toggle_bold(imhtml);
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5597
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5598 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_italic") != imhtml->edit.italic)
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5599 gtk_imhtml_toggle_italic(imhtml);
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5600
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5601 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_underline") != imhtml->edit.underline)
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5602 gtk_imhtml_toggle_underline(imhtml);
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5603
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5604 gtk_imhtml_toggle_fontface(imhtml,
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5605 purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/font_face"));
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5606
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5607 if (!(flags & PURPLE_CONNECTION_NO_FONTSIZE))
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5608 {
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5609 int size = purple_prefs_get_int(PIDGIN_PREFS_ROOT "/conversations/font_size");
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5610
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5611 /* 3 is the default. */
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5612 if (size != 3)
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5613 gtk_imhtml_font_set_size(imhtml, size);
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5614 }
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5615
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5616 if(strcmp(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/fgcolor"), "") != 0)
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5617 {
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5618 gdk_color_parse(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/fgcolor"),
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5619 &fg_color);
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5620 g_snprintf(color, sizeof(color), "#%02x%02x%02x",
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5621 fg_color.red / 256,
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5622 fg_color.green / 256,
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5623 fg_color.blue / 256);
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5624 } else
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5625 strcpy(color, "");
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5626
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5627 gtk_imhtml_toggle_forecolor(imhtml, color);
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5628
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5629 if(!(flags & PURPLE_CONNECTION_NO_BGCOLOR) &&
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5630 strcmp(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/bgcolor"), "") != 0)
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5631 {
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5632 gdk_color_parse(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/bgcolor"),
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5633 &bg_color);
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5634 g_snprintf(color, sizeof(color), "#%02x%02x%02x",
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5635 bg_color.red / 256,
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5636 bg_color.green / 256,
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5637 bg_color.blue / 256);
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5638 } else
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5639 strcpy(color, "");
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5640
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5641 gtk_imhtml_toggle_background(imhtml, color);
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5642
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5643 if (flags & PURPLE_CONNECTION_FORMATTING_WBFO)
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5644 gtk_imhtml_set_whole_buffer_formatting_only(imhtml, TRUE);
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5645 else
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5646 gtk_imhtml_set_whole_buffer_formatting_only(imhtml, FALSE);
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5647 } else {
18240
0a7d2fde749b Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 18185
diff changeset
5648 buttons = GTK_IMHTML_SMILEY | GTK_IMHTML_IMAGE;
17388
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5649 imhtml_clear_formatting(imhtml);
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5650 }
18240
0a7d2fde749b Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 18185
diff changeset
5651
0a7d2fde749b Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 18185
diff changeset
5652 if (flags & PURPLE_CONNECTION_NO_IMAGES)
0a7d2fde749b Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 18185
diff changeset
5653 buttons &= ~GTK_IMHTML_IMAGE;
0a7d2fde749b Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 18185
diff changeset
5654
23010
6230fac29cee Show the custom smileys only on accounts that support it. References
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23008
diff changeset
5655 if (flags & PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY)
6230fac29cee Show the custom smileys only on accounts that support it. References
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23008
diff changeset
5656 buttons |= GTK_IMHTML_CUSTOM_SMILEY;
6230fac29cee Show the custom smileys only on accounts that support it. References
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23008
diff changeset
5657 else
6230fac29cee Show the custom smileys only on accounts that support it. References
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23008
diff changeset
5658 buttons &= ~GTK_IMHTML_CUSTOM_SMILEY;
6230fac29cee Show the custom smileys only on accounts that support it. References
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23008
diff changeset
5659
18240
0a7d2fde749b Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 18185
diff changeset
5660 gtk_imhtml_set_format_functions(imhtml, buttons);
17388
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5661 }
8be39f0de528 Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17288
diff changeset
5662
22655
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5663 /*******
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5664 * GtkIMHtmlSmiley functions
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5665 *******/
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5666 static void gtk_custom_smiley_allocated(GdkPixbufLoader *loader, gpointer user_data)
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5667 {
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5668 GtkIMHtmlSmiley *smiley;
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5669
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5670 smiley = (GtkIMHtmlSmiley *)user_data;
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5671 smiley->icon = gdk_pixbuf_loader_get_animation(loader);
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5672
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5673 if (smiley->icon)
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5674 g_object_ref(G_OBJECT(smiley->icon));
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5675 #ifdef DEBUG_CUSTOM_SMILEY
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5676 purple_debug_info("custom-smiley", "gtk_custom_smiley_allocated(): got GdkPixbufAnimation %p for smiley '%s'\n", smiley->icon, smiley->smile);
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5677 #endif
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5678 }
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5679
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5680 static void gtk_custom_smiley_closed(GdkPixbufLoader *loader, gpointer user_data)
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5681 {
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5682 GtkIMHtmlSmiley *smiley;
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5683 GtkWidget *icon = NULL;
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5684 GtkTextChildAnchor *anchor = NULL;
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5685 GSList *current = NULL;
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5686
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5687 smiley = (GtkIMHtmlSmiley *)user_data;
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5688 if (!smiley->imhtml) {
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5689 #ifdef DEBUG_CUSTOM_SMILEY
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5690 purple_debug_error("custom-smiley", "gtk_custom_smiley_closed(): orphan smiley found: %p\n", smiley);
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5691 #endif
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5692 g_object_unref(G_OBJECT(loader));
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5693 smiley->loader = NULL;
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5694 return;
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5695 }
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5696
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5697 for (current = smiley->anchors; current; current = g_slist_next(current)) {
23398
4de581ccaf1e Do not try to update received custom smileys in a deleted child anchor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23377
diff changeset
5698 anchor = GTK_TEXT_CHILD_ANCHOR(current->data);
4de581ccaf1e Do not try to update received custom smileys in a deleted child anchor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23377
diff changeset
5699 if (gtk_text_child_anchor_get_deleted(anchor))
4de581ccaf1e Do not try to update received custom smileys in a deleted child anchor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23377
diff changeset
5700 icon = NULL;
4de581ccaf1e Do not try to update received custom smileys in a deleted child anchor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23377
diff changeset
5701 else
4de581ccaf1e Do not try to update received custom smileys in a deleted child anchor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23377
diff changeset
5702 icon = gtk_image_new_from_animation(smiley->icon);
22655
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5703
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5704 #ifdef DEBUG_CUSTOM_SMILEY
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5705 purple_debug_info("custom-smiley", "gtk_custom_smiley_closed(): got GtkImage %p from GtkPixbufAnimation %p for smiley '%s'\n",
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5706 icon, smiley->icon, smiley->smile);
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5707 #endif
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5708 if (icon) {
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5709 GList *wids;
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5710 gtk_widget_show(icon);
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5711
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5712 wids = gtk_text_child_anchor_get_widgets(anchor);
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5713
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5714 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_plaintext", purple_unescape_html(smiley->smile), g_free);
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5715 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_htmltext", g_strdup(smiley->smile), g_free);
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5716
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5717 if (smiley->imhtml) {
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5718 if (wids) {
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5719 GList *children = gtk_container_get_children(GTK_CONTAINER(wids->data));
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5720 g_list_foreach(children, (GFunc)gtk_widget_destroy, NULL);
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5721 g_list_free(children);
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5722 gtk_container_add(GTK_CONTAINER(wids->data), icon);
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5723 } else
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5724 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(smiley->imhtml), icon, anchor);
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5725 }
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5726 g_list_free(wids);
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5727 }
23398
4de581ccaf1e Do not try to update received custom smileys in a deleted child anchor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23377
diff changeset
5728 g_object_unref(anchor);
22655
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5729 }
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5730
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5731 g_slist_free(smiley->anchors);
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5732 smiley->anchors = NULL;
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5733
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5734 g_object_unref(G_OBJECT(loader));
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5735 smiley->loader = NULL;
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5736 }
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5737
23018
39c5be5ca1e9 Patch from Masca to restrict the size of incoming custom smileys to a
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23010
diff changeset
5738 static void
39c5be5ca1e9 Patch from Masca to restrict the size of incoming custom smileys to a
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23010
diff changeset
5739 gtk_custom_smiley_size_prepared(GdkPixbufLoader *loader, gint width, gint height, gpointer data)
39c5be5ca1e9 Patch from Masca to restrict the size of incoming custom smileys to a
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23010
diff changeset
5740 {
39c5be5ca1e9 Patch from Masca to restrict the size of incoming custom smileys to a
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23010
diff changeset
5741 #define CUSTOM_SMILEY_SIZE 96 /* XXX: Should this be a theme setting? */
39c5be5ca1e9 Patch from Masca to restrict the size of incoming custom smileys to a
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23010
diff changeset
5742 if (width <= CUSTOM_SMILEY_SIZE && height <= CUSTOM_SMILEY_SIZE)
39c5be5ca1e9 Patch from Masca to restrict the size of incoming custom smileys to a
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23010
diff changeset
5743 return;
39c5be5ca1e9 Patch from Masca to restrict the size of incoming custom smileys to a
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23010
diff changeset
5744
39c5be5ca1e9 Patch from Masca to restrict the size of incoming custom smileys to a
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23010
diff changeset
5745 if (width >= height) {
39c5be5ca1e9 Patch from Masca to restrict the size of incoming custom smileys to a
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23010
diff changeset
5746 height = height * CUSTOM_SMILEY_SIZE / width;
39c5be5ca1e9 Patch from Masca to restrict the size of incoming custom smileys to a
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23010
diff changeset
5747 width = CUSTOM_SMILEY_SIZE;
39c5be5ca1e9 Patch from Masca to restrict the size of incoming custom smileys to a
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23010
diff changeset
5748 } else {
39c5be5ca1e9 Patch from Masca to restrict the size of incoming custom smileys to a
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23010
diff changeset
5749 width = width * CUSTOM_SMILEY_SIZE / height;
39c5be5ca1e9 Patch from Masca to restrict the size of incoming custom smileys to a
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23010
diff changeset
5750 height = CUSTOM_SMILEY_SIZE;
39c5be5ca1e9 Patch from Masca to restrict the size of incoming custom smileys to a
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23010
diff changeset
5751 }
39c5be5ca1e9 Patch from Masca to restrict the size of incoming custom smileys to a
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23010
diff changeset
5752
39c5be5ca1e9 Patch from Masca to restrict the size of incoming custom smileys to a
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23010
diff changeset
5753 gdk_pixbuf_loader_set_size(loader, width, height);
39c5be5ca1e9 Patch from Masca to restrict the size of incoming custom smileys to a
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23010
diff changeset
5754 }
39c5be5ca1e9 Patch from Masca to restrict the size of incoming custom smileys to a
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23010
diff changeset
5755
22655
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5756 void
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5757 gtk_imhtml_smiley_reload(GtkIMHtmlSmiley *smiley)
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5758 {
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5759 if (smiley->icon)
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5760 g_object_unref(smiley->icon);
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5761 if (smiley->loader)
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5762 g_object_unref(smiley->loader); /* XXX: does this crash? */
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5763
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5764 smiley->icon = NULL;
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5765 smiley->loader = NULL;
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5766
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5767 if (smiley->file) {
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5768 /* We do not use the pixbuf loader for a smiley that can be loaded
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5769 * from a file. (e.g., local custom smileys)
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5770 */
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5771 return;
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5772 }
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5773
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5774 smiley->loader = gdk_pixbuf_loader_new();
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5775
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5776 g_signal_connect(smiley->loader, "area_prepared", G_CALLBACK(gtk_custom_smiley_allocated), smiley);
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5777 g_signal_connect(smiley->loader, "closed", G_CALLBACK(gtk_custom_smiley_closed), smiley);
23018
39c5be5ca1e9 Patch from Masca to restrict the size of incoming custom smileys to a
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23010
diff changeset
5778 g_signal_connect(smiley->loader, "size_prepared", G_CALLBACK(gtk_custom_smiley_size_prepared), smiley);
22655
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5779 }
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5780
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5781 GtkIMHtmlSmiley *gtk_imhtml_smiley_create(const char *file, const char *shortcut, gboolean hide,
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5782 GtkIMHtmlSmileyFlags flags)
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5783 {
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5784 GtkIMHtmlSmiley *smiley = g_new0(GtkIMHtmlSmiley, 1);
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5785 smiley->file = g_strdup(file);
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5786 smiley->smile = g_strdup(shortcut);
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5787 smiley->hidden = hide;
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5788 smiley->flags = flags;
24392
51b7f65a712d Clean up the GtkSmileyTrees on active GtkIMHtml instances when a custom smiley
Marcus Lundblad <malu@pidgin.im>
parents: 24328
diff changeset
5789 smiley->imhtml = NULL;
22655
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5790 gtk_imhtml_smiley_reload(smiley);
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5791 return smiley;
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5792 }
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5793
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5794 void gtk_imhtml_smiley_destroy(GtkIMHtmlSmiley *smiley)
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5795 {
24392
51b7f65a712d Clean up the GtkSmileyTrees on active GtkIMHtml instances when a custom smiley
Marcus Lundblad <malu@pidgin.im>
parents: 24328
diff changeset
5796 gtk_imhtml_disassociate_smiley(smiley);
22655
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5797 g_free(smiley->smile);
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5798 g_free(smiley->file);
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5799 if (smiley->icon)
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5800 g_object_unref(smiley->icon);
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5801 if (smiley->loader)
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5802 g_object_unref(smiley->loader);
27123
90abaa4562b3 Save raw-data for an image when possible.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27122
diff changeset
5803 g_free(smiley->data);
22655
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5804 g_free(smiley);
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5805 }
718f1149a81c Introduce API for GtkIMHtmlSmiley. Use this to prevent leaking remote custom emoticons.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22532
diff changeset
5806
24674
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
5807 gboolean gtk_imhtml_class_register_protocol(const char *name,
24698
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5808 gboolean (*activate)(GtkIMHtml *imhtml, GtkIMHtmlLink *link),
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5809 gboolean (*context_menu)(GtkIMHtml *imhtml, GtkIMHtmlLink *link, GtkWidget *menu))
24674
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
5810 {
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
5811 GtkIMHtmlClass *klass;
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
5812 GtkIMHtmlProtocol *proto;
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
5813
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
5814 g_return_val_if_fail(name, FALSE);
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
5815
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
5816 klass = g_type_class_ref(GTK_TYPE_IMHTML);
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
5817 g_return_val_if_fail(klass, FALSE);
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
5818
25013
956b2f650d31 Detect duplication registrations by substring.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 25011
diff changeset
5819 if ((proto = imhtml_find_protocol(name, TRUE))) {
25014
5bf71146f93e Replace the URL registration assertions with regular checks.
Richard Laager <rlaager@pidgin.im>
parents: 25013
diff changeset
5820 if (activate) {
5bf71146f93e Replace the URL registration assertions with regular checks.
Richard Laager <rlaager@pidgin.im>
parents: 25013
diff changeset
5821 return FALSE;
5bf71146f93e Replace the URL registration assertions with regular checks.
Richard Laager <rlaager@pidgin.im>
parents: 25013
diff changeset
5822 }
28077
c2b493e058f1 Don't use pointers (even opaquely) once they're freed. Closes #9822.
Paul Aurich <darkrain42@pidgin.im>
parents: 27525
diff changeset
5823 klass->protocols = g_list_remove(klass->protocols, proto);
24674
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
5824 g_free(proto->name);
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
5825 g_free(proto);
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
5826 return TRUE;
25014
5bf71146f93e Replace the URL registration assertions with regular checks.
Richard Laager <rlaager@pidgin.im>
parents: 25013
diff changeset
5827 } else if (!activate) {
5bf71146f93e Replace the URL registration assertions with regular checks.
Richard Laager <rlaager@pidgin.im>
parents: 25013
diff changeset
5828 return FALSE;
24674
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
5829 }
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
5830
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
5831 proto = g_new0(GtkIMHtmlProtocol, 1);
25008
f52b9372eb19 Revert the URL scheme passing changes, keeping the miscellaneous other stuff
Richard Laager <rlaager@pidgin.im>
parents: 25007
diff changeset
5832 proto->name = g_strdup(name);
f52b9372eb19 Revert the URL scheme passing changes, keeping the miscellaneous other stuff
Richard Laager <rlaager@pidgin.im>
parents: 25007
diff changeset
5833 proto->length = strlen(name);
24674
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
5834 proto->activate = activate;
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
5835 proto->context_menu = context_menu;
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
5836 klass->protocols = g_list_prepend(klass->protocols, proto);
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
5837
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
5838 return TRUE;
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
5839 }
36bf974a7d78 Allow plugins to specify custom link types to the GtkIMHtml widget.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24588
diff changeset
5840
24698
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5841 static void
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5842 gtk_imhtml_activate_tag(GtkIMHtml *imhtml, GtkTextTag *tag)
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5843 {
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5844 /* A link was clicked--we emit the "url_clicked" signal
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5845 * with the URL as the argument */
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5846 g_object_ref(G_OBJECT(tag));
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5847 g_signal_emit(imhtml, signals[URL_CLICKED], 0, g_object_get_data(G_OBJECT(tag), "link_url"));
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5848 g_object_unref(G_OBJECT(tag));
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5849 g_object_set_data(G_OBJECT(tag), "visited", GINT_TO_POINTER(TRUE));
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5850 gtk_imhtml_set_link_color(GTK_IMHTML(imhtml), tag);
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5851 }
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5852
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5853 gboolean gtk_imhtml_link_activate(GtkIMHtmlLink *link)
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5854 {
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5855 g_return_val_if_fail(link, FALSE);
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5856
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5857 if (link->tag) {
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5858 gtk_imhtml_activate_tag(link->imhtml, link->tag);
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5859 } else if (link->url) {
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5860 g_signal_emit(link->imhtml, signals[URL_CLICKED], 0, link->url);
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5861 } else
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5862 return FALSE;
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5863 return TRUE;
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5864 }
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5865
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5866 const char *gtk_imhtml_link_get_url(GtkIMHtmlLink *link)
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5867 {
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5868 return link->url;
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5869 }
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5870
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5871 const GtkTextTag * gtk_imhtml_link_get_text_tag(GtkIMHtmlLink *link)
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5872 {
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5873 return link->tag;
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5874 }
f9dd7117ade0 Clean up some crufts. I think this is now mergeable with .next.minor.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24675
diff changeset
5875
25900
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5876 static gboolean return_add_newline_cb(GtkWidget *widget, gpointer data)
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5877 {
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5878 GtkTextBuffer *buffer;
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5879 GtkTextMark *mark;
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5880 GtkTextIter iter;
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5881
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5882 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget));
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5883
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5884 /* Delete any currently selected text */
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5885 gtk_text_buffer_delete_selection(buffer, TRUE, TRUE);
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5886
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5887 /* Insert a newline at the current cursor position */
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5888 mark = gtk_text_buffer_get_insert(buffer);
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5889 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5890 gtk_imhtml_insert_html_at_iter(GTK_IMHTML(widget), "\n", 0, &iter);
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5891
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5892 /*
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5893 * If we just newlined ourselves past the end of the visible area
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5894 * then scroll down so the cursor is in view.
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5895 */
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5896 gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(widget),
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5897 gtk_text_buffer_get_insert(buffer),
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5898 0, FALSE, 0.0, 0.0);
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5899
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5900 return TRUE;
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5901 }
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5902
25906
a64c9c871a23 Add a comment just noting that I think it's kind of annoying that we
Mark Doliner <markdoliner@pidgin.im>
parents: 25905
diff changeset
5903 /*
a64c9c871a23 Add a comment just noting that I think it's kind of annoying that we
Mark Doliner <markdoliner@pidgin.im>
parents: 25905
diff changeset
5904 * It's kind of a pain that we need this function and the above just
a64c9c871a23 Add a comment just noting that I think it's kind of annoying that we
Mark Doliner <markdoliner@pidgin.im>
parents: 25905
diff changeset
5905 * to reinstate the default GtkTextView behavior. It might be better
a64c9c871a23 Add a comment just noting that I think it's kind of annoying that we
Mark Doliner <markdoliner@pidgin.im>
parents: 25905
diff changeset
5906 * if GtkIMHtml didn't intercept the enter key and just required the
a64c9c871a23 Add a comment just noting that I think it's kind of annoying that we
Mark Doliner <markdoliner@pidgin.im>
parents: 25905
diff changeset
5907 * application to deal with it--it's really not much more work than it
a64c9c871a23 Add a comment just noting that I think it's kind of annoying that we
Mark Doliner <markdoliner@pidgin.im>
parents: 25905
diff changeset
5908 * is to connect to the current "message_send" signal.
a64c9c871a23 Add a comment just noting that I think it's kind of annoying that we
Mark Doliner <markdoliner@pidgin.im>
parents: 25905
diff changeset
5909 */
25900
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5910 void gtk_imhtml_set_return_inserts_newline(GtkIMHtml *imhtml)
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5911 {
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5912 g_signal_connect(G_OBJECT(imhtml), "message_send",
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5913 G_CALLBACK(return_add_newline_cb), NULL);
0be61f1b3dd1 Add a GtkIMHtml function that causes the widget to actually insert a
Mark Doliner <markdoliner@pidgin.im>
parents: 25899
diff changeset
5914 }
27032
991e2899be82 Avoid overwriting the PRIMARY clipboard when we select-on-focus the status text for easy editing. Fixes #8781.
Daniel Atallah <datallah@pidgin.im>
parents: 27031
diff changeset
5915
991e2899be82 Avoid overwriting the PRIMARY clipboard when we select-on-focus the status text for easy editing. Fixes #8781.
Daniel Atallah <datallah@pidgin.im>
parents: 27031
diff changeset
5916 void gtk_imhtml_set_populate_primary_clipboard(GtkIMHtml *imhtml, gboolean populate)
991e2899be82 Avoid overwriting the PRIMARY clipboard when we select-on-focus the status text for easy editing. Fixes #8781.
Daniel Atallah <datallah@pidgin.im>
parents: 27031
diff changeset
5917 {
27114
63f35ec28622 Block/Unblock the signal handler when if it's unblocked/blocked.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27032
diff changeset
5918 gulong signal_id;
63f35ec28622 Block/Unblock the signal handler when if it's unblocked/blocked.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27032
diff changeset
5919 signal_id = g_signal_handler_find(imhtml->text_buffer,
63f35ec28622 Block/Unblock the signal handler when if it's unblocked/blocked.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27032
diff changeset
5920 G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_UNBLOCKED, 0, 0, NULL,
63f35ec28622 Block/Unblock the signal handler when if it's unblocked/blocked.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27032
diff changeset
5921 mark_set_so_update_selection_cb, NULL);
27032
991e2899be82 Avoid overwriting the PRIMARY clipboard when we select-on-focus the status text for easy editing. Fixes #8781.
Daniel Atallah <datallah@pidgin.im>
parents: 27031
diff changeset
5922 if (populate) {
27114
63f35ec28622 Block/Unblock the signal handler when if it's unblocked/blocked.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27032
diff changeset
5923 if (!signal_id) {
63f35ec28622 Block/Unblock the signal handler when if it's unblocked/blocked.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27032
diff changeset
5924 /* We didn't find an unblocked signal handler, which means there
63f35ec28622 Block/Unblock the signal handler when if it's unblocked/blocked.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27032
diff changeset
5925 is a blocked handler. Now unblock it.
63f35ec28622 Block/Unblock the signal handler when if it's unblocked/blocked.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27032
diff changeset
5926 This is necessary to avoid a mutex-lock when the debug message
63f35ec28622 Block/Unblock the signal handler when if it's unblocked/blocked.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27032
diff changeset
5927 saying 'no handler is blocked' is printed in the debug window.
63f35ec28622 Block/Unblock the signal handler when if it's unblocked/blocked.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27032
diff changeset
5928 -- sad
63f35ec28622 Block/Unblock the signal handler when if it's unblocked/blocked.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27032
diff changeset
5929 */
63f35ec28622 Block/Unblock the signal handler when if it's unblocked/blocked.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27032
diff changeset
5930 g_signal_handlers_unblock_matched(imhtml->text_buffer,
63f35ec28622 Block/Unblock the signal handler when if it's unblocked/blocked.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27032
diff changeset
5931 G_SIGNAL_MATCH_FUNC, 0, 0, NULL,
63f35ec28622 Block/Unblock the signal handler when if it's unblocked/blocked.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27032
diff changeset
5932 mark_set_so_update_selection_cb, NULL);
63f35ec28622 Block/Unblock the signal handler when if it's unblocked/blocked.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27032
diff changeset
5933 }
27032
991e2899be82 Avoid overwriting the PRIMARY clipboard when we select-on-focus the status text for easy editing. Fixes #8781.
Daniel Atallah <datallah@pidgin.im>
parents: 27031
diff changeset
5934 } else {
27114
63f35ec28622 Block/Unblock the signal handler when if it's unblocked/blocked.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27032
diff changeset
5935 /* Block only if we found an unblocked handler */
63f35ec28622 Block/Unblock the signal handler when if it's unblocked/blocked.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27032
diff changeset
5936 if (signal_id)
63f35ec28622 Block/Unblock the signal handler when if it's unblocked/blocked.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 27032
diff changeset
5937 g_signal_handler_block(imhtml->text_buffer, signal_id);
27032
991e2899be82 Avoid overwriting the PRIMARY clipboard when we select-on-focus the status text for easy editing. Fixes #8781.
Daniel Atallah <datallah@pidgin.im>
parents: 27031
diff changeset
5938 }
991e2899be82 Avoid overwriting the PRIMARY clipboard when we select-on-focus the status text for easy editing. Fixes #8781.
Daniel Atallah <datallah@pidgin.im>
parents: 27031
diff changeset
5939 }

mercurial