Sat, 28 Jul 2007 20:52:06 +0000
merge of '9c330708f8380069a784a5b1a5c0003f2a25dd59'
and '9a8d8bfe9de253c2d6086ad5fc8ef4d4acbe1bcc'
| 1428 | 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 |
|
10297
b36800725b7a
[gaim-migrate @ 11480]
Evan Schoenberg <evands@pidgin.im>
parents:
10243
diff
changeset
|
4 | * |
|
15931
716b5fac1895
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
5 | * pidgin |
| 1428 | 6 | * |
|
15931
716b5fac1895
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
7 | * Pidgin is the legal property of its developers, whose names are too numerous |
| 8046 | 8 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 9 | * source distribution. | |
| 1428 | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify | |
| 12 | * under the terms of the GNU General Public License as published by | |
| 13 | * the Free Software Foundation; either version 2 of the License, or | |
| 14 | * (at your option) any later version. | |
| 15 | * | |
| 16 | * This program is distributed in the hope that it will be useful, | |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 19 | * GNU General Public License for more details. | |
| 20 | * | |
| 21 | * You should have received a copy of the GNU General Public License | |
| 22 | * along with this program; if not, write to the Free Software | |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 24 | * | |
| 25 | */ | |
| 26 | ||
|
2541
0afd3aaba327
[gaim-migrate @ 2554]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2365
diff
changeset
|
27 | #ifdef HAVE_CONFIG_H |
|
0afd3aaba327
[gaim-migrate @ 2554]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2365
diff
changeset
|
28 | #include <config.h> |
|
0afd3aaba327
[gaim-migrate @ 2554]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2365
diff
changeset
|
29 | #endif |
|
18119
699d876e3db0
Include pidgin.h to make this compile.
Richard Laager <rlaager@pidgin.im>
parents:
18108
diff
changeset
|
30 | |
|
18633
34ba43198355
Fix the win32 build. Thanks to Etan and Lee Roach. Fixes #1929.
Daniel Atallah <datallah@pidgin.im>
parents:
18552
diff
changeset
|
31 | #include "internal.h" |
|
18119
699d876e3db0
Include pidgin.h to make this compile.
Richard Laager <rlaager@pidgin.im>
parents:
18108
diff
changeset
|
32 | #include "pidgin.h" |
|
699d876e3db0
Include pidgin.h to make this compile.
Richard Laager <rlaager@pidgin.im>
parents:
18108
diff
changeset
|
33 | |
| 8526 | 34 | #include "debug.h" |
| 8091 | 35 | #include "util.h" |
| 1428 | 36 | #include "gtkimhtml.h" |
| 7358 | 37 | #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
|
38 | #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
|
39 | #include "gtksourceview-marshal.h" |
| 1428 | 40 | #include <gtk/gtk.h> |
| 4895 | 41 | #include <glib/gerror.h> |
| 4046 | 42 | #include <gdk/gdkkeysyms.h> |
| 1428 | 43 | #include <string.h> |
| 44 | #include <ctype.h> | |
| 45 | #include <stdio.h> | |
|
4629
7ac4830de853
[gaim-migrate @ 4920]
Mark Doliner <markdoliner@pidgin.im>
parents:
4612
diff
changeset
|
46 | #include <stdlib.h> |
| 1428 | 47 | #include <math.h> |
|
2541
0afd3aaba327
[gaim-migrate @ 2554]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2365
diff
changeset
|
48 | #ifdef HAVE_LANGINFO_CODESET |
|
0afd3aaba327
[gaim-migrate @ 2554]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2365
diff
changeset
|
49 | #include <langinfo.h> |
|
0afd3aaba327
[gaim-migrate @ 2554]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2365
diff
changeset
|
50 | #include <locale.h> |
|
0afd3aaba327
[gaim-migrate @ 2554]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2365
diff
changeset
|
51 | #endif |
| 8692 | 52 | #ifdef _WIN32 |
|
10901
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
53 | #include <gdk/gdkwin32.h> |
| 8692 | 54 | #include <windows.h> |
| 55 | #endif | |
| 1428 | 56 | |
| 4735 | 57 | #include <pango/pango-font.h> |
| 58 | ||
| 15577 | 59 | /* GTK+ < 2.4.x hack, see pidgin.h for details. */ |
|
10062
144767f0643a
[gaim-migrate @ 11037]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10016
diff
changeset
|
60 | #if (!GTK_CHECK_VERSION(2,4,0)) |
|
5105
3565a4c4de6a
[gaim-migrate @ 5468]
David J. Brigada <brigada@prism.net>
parents:
5104
diff
changeset
|
61 | #define GTK_WRAP_WORD_CHAR GTK_WRAP_WORD |
|
3565a4c4de6a
[gaim-migrate @ 5468]
David J. Brigada <brigada@prism.net>
parents:
5104
diff
changeset
|
62 | #endif |
|
3565a4c4de6a
[gaim-migrate @ 5468]
David J. Brigada <brigada@prism.net>
parents:
5104
diff
changeset
|
63 | |
| 4735 | 64 | #define TOOLTIP_TIMEOUT 500 |
| 65 | ||
| 8786 | 66 | /* GTK+ 2.0 hack */ |
| 67 | #if (!GTK_CHECK_VERSION(2,2,0)) | |
| 68 | #define gtk_widget_get_clipboard(x, y) gtk_clipboard_get(y) | |
| 69 | #endif | |
| 70 | ||
| 10100 | 71 | static GtkTextViewClass *parent_class = NULL; |
| 72 | ||
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
73 | struct scalable_data { |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
74 | GtkIMHtmlScalable *scalable; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
75 | GtkTextMark *mark; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
76 | }; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
77 | |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
78 | |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
79 | struct im_image_data { |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
80 | int id; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
81 | GtkTextMark *mark; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
82 | }; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
83 | |
| 9300 | 84 | static gboolean |
| 85 | gtk_text_view_drag_motion (GtkWidget *widget, | |
| 86 | GdkDragContext *context, | |
| 87 | gint x, | |
| 88 | gint y, | |
| 89 | guint time); | |
| 90 | ||
| 8677 | 91 | static void preinsert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml); |
| 8061 | 92 | 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
|
93 | static void delete_cb(GtkTextBuffer *buffer, GtkTextIter *iter, GtkTextIter *end, GtkIMHtml *imhtml); |
| 10169 | 94 | static void insert_ca_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextChildAnchor *arg2, gpointer user_data); |
| 95 | static void gtk_imhtml_apply_tags_on_insert(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end); | |
| 8698 | 96 | void gtk_imhtml_close_tags(GtkIMHtml *imhtml, GtkTextIter *iter); |
| 9300 | 97 | static void gtk_imhtml_link_drop_cb(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer user_data); |
| 8091 | 98 | 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 | 99 | static void mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, GtkIMHtml *imhtml); |
| 8931 | 100 | static void hijack_menu_cb(GtkIMHtml *imhtml, GtkMenu *menu, gpointer data); |
| 101 | static void paste_received_cb (GtkClipboard *clipboard, GtkSelectionData *selection_data, gpointer data); | |
| 102 | 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
|
103 | 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
|
104 | static void imhtml_toggle_bold(GtkIMHtml *imhtml); |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
105 | static void imhtml_toggle_italic(GtkIMHtml *imhtml); |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
106 | static void imhtml_toggle_strike(GtkIMHtml *imhtml); |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
107 | static void imhtml_toggle_underline(GtkIMHtml *imhtml); |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
108 | static void imhtml_font_grow(GtkIMHtml *imhtml); |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
109 | static void imhtml_font_shrink(GtkIMHtml *imhtml); |
|
12672
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
110 | static void imhtml_clear_formatting(GtkIMHtml *imhtml); |
| 8061 | 111 | |
|
10899
87d9aec5b72d
[gaim-migrate @ 12619]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10871
diff
changeset
|
112 | /* POINT_SIZE converts from AIM font sizes to a point size scale factor. */ |
| 3922 | 113 | #define MAX_FONT_SIZE 7 |
|
10900
cc19dfd83910
[gaim-migrate @ 12621]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10899
diff
changeset
|
114 | #define POINT_SIZE(x) (_point_sizes [MIN ((x > 0 ? x : 1), MAX_FONT_SIZE) - 1]) |
| 14741 | 115 | static 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
|
116 | |
|
10184
543c9a84ce16
[gaim-migrate @ 11299]
Mark Doliner <markdoliner@pidgin.im>
parents:
10169
diff
changeset
|
117 | enum { |
| 8677 | 118 | TARGET_HTML, |
| 8061 | 119 | TARGET_UTF8_STRING, |
| 120 | TARGET_COMPOUND_TEXT, | |
| 121 | TARGET_STRING, | |
| 122 | TARGET_TEXT | |
| 123 | }; | |
| 124 | ||
| 8091 | 125 | enum { |
| 8420 | 126 | URL_CLICKED, |
| 127 | BUTTONS_UPDATE, | |
| 128 | TOGGLE_FORMAT, | |
| 8427 | 129 | CLEAR_FORMAT, |
| 8506 | 130 | UPDATE_FORMAT, |
| 10108 | 131 | 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
|
132 | 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
|
133 | REDO, |
| 8420 | 134 | LAST_SIGNAL |
| 135 | }; | |
| 136 | static guint signals [LAST_SIGNAL] = { 0 }; | |
| 137 | ||
|
17546
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
138 | 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
|
139 | static char *text_clipboard = NULL; |
|
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
140 | GtkClipboard *clipboard_selection = NULL; |
|
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
141 | |
|
10871
c0282a4f2250
[gaim-migrate @ 12558]
Mark Doliner <markdoliner@pidgin.im>
parents:
10865
diff
changeset
|
142 | static GtkTargetEntry selection_targets[] = { |
|
15111
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
143 | #ifndef _WIN32 |
| 8566 | 144 | { "text/html", 0, TARGET_HTML }, |
|
15111
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
145 | #else |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
146 | { "HTML Format", 0, TARGET_HTML }, |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
147 | #endif |
| 8061 | 148 | { "UTF8_STRING", 0, TARGET_UTF8_STRING }, |
| 149 | { "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT }, | |
| 150 | { "STRING", 0, TARGET_STRING }, | |
| 151 | { "TEXT", 0, TARGET_TEXT}}; | |
| 152 | ||
|
10871
c0282a4f2250
[gaim-migrate @ 12558]
Mark Doliner <markdoliner@pidgin.im>
parents:
10865
diff
changeset
|
153 | static GtkTargetEntry link_drag_drop_targets[] = { |
|
10145
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
154 | GTK_IMHTML_DND_TARGETS |
|
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
155 | }; |
| 8091 | 156 | |
| 8692 | 157 | #ifdef _WIN32 |
| 158 | static gchar * | |
| 159 | clipboard_win32_to_html(char *clipboard) { | |
| 9465 | 160 | const char *header; |
| 8693 | 161 | const char *begin, *end; |
|
10016
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
162 | gint start = 0; |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
163 | gint finish = 0; |
| 8692 | 164 | gchar *html; |
|
10016
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
165 | gchar **split; |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
166 | int clipboard_length = 0; |
| 9465 | 167 | |
| 168 | #if 0 /* Debugging for Windows clipboard */ | |
| 9467 | 169 | FILE *fd; |
| 170 | ||
| 15884 | 171 | purple_debug_info("imhtml clipboard", "from clipboard: %s\n", clipboard); |
| 172 | ||
| 173 | fd = g_fopen("e:\\purplecb.txt", "wb"); | |
| 9465 | 174 | fprintf(fd, "%s", clipboard); |
| 175 | fclose(fd); | |
| 176 | #endif | |
| 177 | ||
|
10016
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
178 | clipboard_length = strlen(clipboard); |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
179 | |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
180 | if (!(header = strstr(clipboard, "StartFragment:")) || (header - clipboard) >= clipboard_length) |
| 9465 | 181 | return NULL; |
| 182 | sscanf(header, "StartFragment:%d", &start); | |
| 183 | ||
|
10016
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
184 | if (!(header = strstr(clipboard, "EndFragment:")) || (header - clipboard) >= clipboard_length) |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
185 | return NULL; |
| 9465 | 186 | sscanf(header, "EndFragment:%d", &finish); |
| 187 | ||
|
10016
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
188 | if (finish > clipboard_length) |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
189 | finish = clipboard_length; |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
190 | |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
191 | if (start > finish) |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
192 | start = finish; |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
193 | |
| 9465 | 194 | begin = clipboard + start; |
| 195 | ||
|
10016
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
196 | end = clipboard + finish; |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
197 | |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
198 | html = g_strndup(begin, end - begin); |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
199 | |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
200 | /* 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
|
201 | split = g_strsplit(html, "\r\n", 0); |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
202 | g_free(html); |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
203 | html = g_strjoinv("\n", split); |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
204 | g_strfreev(split); |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
205 | |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
206 | html = g_strstrip(html); |
| 9465 | 207 | |
| 208 | #if 0 /* Debugging for Windows clipboard */ | |
| 15884 | 209 | purple_debug_info("imhtml clipboard", "HTML fragment: '%s'\n", html); |
| 9465 | 210 | #endif |
| 211 | ||
| 8707 | 212 | return html; |
| 8692 | 213 | } |
| 214 | ||
| 215 | static gchar * | |
| 216 | clipboard_html_to_win32(char *html) { | |
| 8693 | 217 | int length; |
|
11240
cd4ca16ff57c
[gaim-migrate @ 13399]
Richard Laager <rlaager@pidgin.im>
parents:
11234
diff
changeset
|
218 | GString *clipboard; |
| 8692 | 219 | |
| 8693 | 220 | if (html == NULL) |
| 221 | return NULL; | |
| 8692 | 222 | |
| 223 | length = strlen(html); | |
| 9465 | 224 | clipboard = g_string_new ("Version:1.0\r\n"); |
| 8692 | 225 | 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
|
226 | g_string_append_printf(clipboard, "EndHTML:%010d\r\n", 147 + length); |
| 9465 | 227 | 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
|
228 | g_string_append_printf(clipboard, "EndFragment:%010d\r\n", 127 + length); |
| 9465 | 229 | g_string_append(clipboard, "<!--StartFragment-->\r\n"); |
| 8692 | 230 | g_string_append(clipboard, html); |
| 9465 | 231 | g_string_append(clipboard, "\r\n<!--EndFragment-->"); |
|
14101
89a79c2a971e
[gaim-migrate @ 16643]
Mark Doliner <markdoliner@pidgin.im>
parents:
14097
diff
changeset
|
232 | |
|
89a79c2a971e
[gaim-migrate @ 16643]
Mark Doliner <markdoliner@pidgin.im>
parents:
14097
diff
changeset
|
233 | return g_string_free(clipboard, FALSE); |
| 8692 | 234 | } |
|
10901
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
235 | |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
236 | static gboolean clipboard_paste_html_win32(GtkIMHtml *imhtml) { |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
237 | gboolean pasted = FALSE; |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
238 | |
|
15111
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
239 | /* Win32 clipboard format value, and functions to convert back and |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
240 | * forth between HTML and the clipboard format. |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
241 | */ |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
242 | static UINT win_html_fmt = 0; |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
243 | |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
244 | /* Register HTML Format as desired clipboard format */ |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
245 | if (!win_html_fmt) |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
246 | win_html_fmt = RegisterClipboardFormat("HTML Format"); |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
247 | |
|
10901
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
248 | if (gtk_text_view_get_editable(GTK_TEXT_VIEW(imhtml)) |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
249 | && IsClipboardFormatAvailable(win_html_fmt)) { |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
250 | gboolean error_reading_clipboard = FALSE; |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
251 | HWND hwnd = GDK_WINDOW_HWND(GTK_WIDGET(imhtml)->window); |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
252 | |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
253 | if (OpenClipboard(hwnd)) { |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
254 | HGLOBAL hdata = GetClipboardData(win_html_fmt); |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
255 | if (hdata == NULL) { |
|
15111
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
256 | if (GetLastError() != ERROR_SUCCESS) |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
257 | error_reading_clipboard = TRUE; |
|
10901
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
258 | } else { |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
259 | char *buffer = GlobalLock(hdata); |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
260 | if (buffer == NULL) { |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
261 | error_reading_clipboard = TRUE; |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
262 | } else { |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
263 | char *text = clipboard_win32_to_html( |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
264 | buffer); |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
265 | imhtml_paste_insert(imhtml, text, |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
266 | FALSE); |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
267 | g_free(text); |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
268 | pasted = TRUE; |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
269 | } |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
270 | GlobalUnlock(hdata); |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
271 | } |
|
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 | CloseClipboard(); |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
274 | } else { |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
275 | error_reading_clipboard = TRUE; |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
276 | } |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
277 | |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
278 | if (error_reading_clipboard) { |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
279 | gchar *err_msg = g_win32_error_message(GetLastError()); |
| 15884 | 280 | purple_debug_info("html clipboard", |
|
10901
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
281 | "Unable to read clipboard data: %s\n", |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
282 | err_msg ? err_msg : "Unknown Error"); |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
283 | g_free(err_msg); |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
284 | } |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
285 | } |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
286 | |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
287 | return pasted; |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
288 | } |
| 8692 | 289 | #endif |
| 290 | ||
| 4032 | 291 | static GtkSmileyTree* |
| 292 | gtk_smiley_tree_new () | |
| 293 | { | |
| 294 | return g_new0 (GtkSmileyTree, 1); | |
| 295 | } | |
| 296 | ||
| 297 | static void | |
| 298 | gtk_smiley_tree_insert (GtkSmileyTree *tree, | |
| 4263 | 299 | GtkIMHtmlSmiley *smiley) |
| 4032 | 300 | { |
| 301 | GtkSmileyTree *t = tree; | |
| 4263 | 302 | const gchar *x = smiley->smile; |
| 4032 | 303 | |
|
12229
ad8d3ae8fc1b
[gaim-migrate @ 14531]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12072
diff
changeset
|
304 | if (!(*x)) |
| 4032 | 305 | return; |
| 306 | ||
|
12229
ad8d3ae8fc1b
[gaim-migrate @ 14531]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12072
diff
changeset
|
307 | do { |
| 4032 | 308 | gchar *pos; |
| 309 | gint index; | |
| 310 | ||
| 311 | if (!t->values) | |
| 312 | t->values = g_string_new (""); | |
| 313 | ||
| 314 | pos = strchr (t->values->str, *x); | |
| 315 | if (!pos) { | |
| 316 | t->values = g_string_append_c (t->values, *x); | |
| 317 | index = t->values->len - 1; | |
| 318 | t->children = g_realloc (t->children, t->values->len * sizeof (GtkSmileyTree *)); | |
| 319 | t->children [index] = g_new0 (GtkSmileyTree, 1); | |
| 320 | } else | |
| 7386 | 321 | index = GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str); |
| 8061 | 322 | |
| 4032 | 323 | t = t->children [index]; |
| 8061 | 324 | |
| 4032 | 325 | x++; |
|
12229
ad8d3ae8fc1b
[gaim-migrate @ 14531]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12072
diff
changeset
|
326 | } while (*x); |
| 8061 | 327 | |
| 4263 | 328 | t->image = smiley; |
| 4032 | 329 | } |
| 4041 | 330 | |
| 4263 | 331 | |
|
11677
89c2ab8d2ebf
[gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents:
11586
diff
changeset
|
332 | static void |
|
89c2ab8d2ebf
[gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents:
11586
diff
changeset
|
333 | gtk_smiley_tree_destroy (GtkSmileyTree *tree) |
| 4032 | 334 | { |
|
11701
8cf812de5e92
[gaim-migrate @ 13992]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
11677
diff
changeset
|
335 | GSList *list = g_slist_prepend (NULL, tree); |
| 4032 | 336 | |
| 337 | while (list) { | |
| 338 | GtkSmileyTree *t = list->data; | |
|
12229
ad8d3ae8fc1b
[gaim-migrate @ 14531]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12072
diff
changeset
|
339 | gsize i; |
| 4032 | 340 | list = g_slist_remove(list, t); |
| 7384 | 341 | if (t && t->values) { |
| 4032 | 342 | for (i = 0; i < t->values->len; i++) |
|
11701
8cf812de5e92
[gaim-migrate @ 13992]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
11677
diff
changeset
|
343 | list = g_slist_prepend (list, t->children [i]); |
| 4032 | 344 | g_string_free (t->values, TRUE); |
| 345 | g_free (t->children); | |
| 346 | } | |
| 347 | g_free (t); | |
| 348 | } | |
| 349 | } | |
| 350 | ||
|
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
|
351 | 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
|
352 | |
|
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
|
353 | static void gtk_imhtml_size_allocate(GtkWidget *widget, GtkAllocation *alloc) |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
354 | { |
|
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
|
355 | GtkIMHtml *imhtml = GTK_IMHTML(widget); |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
356 | GdkRectangle rect; |
| 8726 | 357 | 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
|
358 | 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
|
359 | 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
|
360 | 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
|
361 | |
|
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
|
362 | gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
363 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
364 | gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(widget), &rect); |
|
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
|
365 | gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(imhtml), &iter, &y, &height); |
|
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
|
366 | |
|
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
|
367 | if(((y + height) - (rect.y + rect.height)) > height |
|
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
|
368 | && gtk_text_buffer_get_char_count(imhtml->text_buffer)){ |
|
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
|
369 | scroll = FALSE; |
|
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
|
370 | } |
|
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
|
371 | |
|
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 | 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
|
373 | GList *iter = GTK_IMHTML(widget)->scalables; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
374 | |
| 8726 | 375 | xminus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(widget)) + |
| 376 | gtk_text_view_get_right_margin(GTK_TEXT_VIEW(widget)); | |
| 377 | ||
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
378 | while(iter){ |
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
379 | struct scalable_data *sd = iter->data; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
380 | GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(sd->scalable); |
| 8726 | 381 | scale->scale(scale, rect.width - xminus, rect.height); |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
382 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
383 | iter = iter->next; |
|
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 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
386 | |
|
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
|
387 | 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
|
388 | parent_size_allocate(widget, 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
|
389 | gtk_imhtml_scroll_to_end(imhtml, FALSE); |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
390 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
391 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
392 | static gint |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
393 | gtk_imhtml_tip_paint (GtkIMHtml *imhtml) |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
394 | { |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
395 | PangoLayout *layout; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
396 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
397 | g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
398 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
399 | layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
400 | |
| 8061 | 401 | gtk_paint_flat_box (imhtml->tip_window->style, imhtml->tip_window->window, |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
402 | GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, imhtml->tip_window, |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
403 | "tooltip", 0, 0, -1, -1); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
404 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
405 | gtk_paint_layout (imhtml->tip_window->style, imhtml->tip_window->window, GTK_STATE_NORMAL, |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
406 | FALSE, NULL, imhtml->tip_window, NULL, 4, 4, layout); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
407 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
408 | g_object_unref(layout); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
409 | return FALSE; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
410 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
411 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
412 | static gint |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
413 | gtk_imhtml_tip (gpointer data) |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
414 | { |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
415 | GtkIMHtml *imhtml = data; |
| 8526 | 416 | PangoFontMetrics *font_metrics; |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
417 | PangoLayout *layout; |
| 8526 | 418 | PangoFont *font; |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
419 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
420 | gint gap, x, y, h, w, scr_w, baseline_skip; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
421 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
422 | g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
423 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
424 | if (!imhtml->tip || !GTK_WIDGET_DRAWABLE (GTK_WIDGET(imhtml))) { |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
425 | imhtml->tip_timer = 0; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
426 | return FALSE; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
427 | } |
| 8061 | 428 | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
429 | if (imhtml->tip_window){ |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
430 | gtk_widget_destroy (imhtml->tip_window); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
431 | imhtml->tip_window = NULL; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
432 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
433 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
434 | imhtml->tip_timer = 0; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
435 | imhtml->tip_window = gtk_window_new (GTK_WINDOW_POPUP); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
436 | gtk_widget_set_app_paintable (imhtml->tip_window, TRUE); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
437 | gtk_window_set_resizable (GTK_WINDOW (imhtml->tip_window), FALSE); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
438 | gtk_widget_set_name (imhtml->tip_window, "gtk-tooltips"); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
439 | g_signal_connect_swapped (G_OBJECT (imhtml->tip_window), "expose_event", |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
440 | G_CALLBACK (gtk_imhtml_tip_paint), imhtml); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
441 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
442 | gtk_widget_ensure_style (imhtml->tip_window); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
443 | layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip); |
| 8526 | 444 | font = pango_context_load_font(pango_layout_get_context(layout), |
| 445 | imhtml->tip_window->style->font_desc); | |
| 446 | ||
| 447 | if (font == NULL) { | |
| 448 | char *tmp = pango_font_description_to_string( | |
| 449 | imhtml->tip_window->style->font_desc); | |
| 450 | ||
| 15884 | 451 | purple_debug(PURPLE_DEBUG_ERROR, "gtk_imhtml_tip", |
| 8526 | 452 | "pango_context_load_font() couldn't load font: '%s'\n", |
| 453 | tmp); | |
| 454 | g_free(tmp); | |
| 455 | ||
| 456 | return FALSE; | |
| 457 | } | |
| 458 | ||
| 459 | font_metrics = pango_font_get_metrics(font, NULL); | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
460 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
461 | pango_layout_get_pixel_size(layout, &scr_w, NULL); |
| 8526 | 462 | gap = PANGO_PIXELS((pango_font_metrics_get_ascent(font_metrics) + |
| 463 | pango_font_metrics_get_descent(font_metrics))/ 4); | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
464 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
465 | if (gap < 2) |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
466 | gap = 2; |
| 8526 | 467 | baseline_skip = PANGO_PIXELS(pango_font_metrics_get_ascent(font_metrics) + |
| 468 | pango_font_metrics_get_descent(font_metrics)); | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
469 | w = 8 + scr_w; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
470 | h = 8 + baseline_skip; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
471 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
472 | gdk_window_get_pointer (NULL, &x, &y, NULL); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
473 | if (GTK_WIDGET_NO_WINDOW (GTK_WIDGET(imhtml))) |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
474 | y += GTK_WIDGET(imhtml)->allocation.y; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
475 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
476 | scr_w = gdk_screen_width(); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
477 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
478 | x -= ((w >> 1) + 4); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
479 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
480 | if ((x + w) > scr_w) |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
481 | x -= (x + w) - scr_w; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
482 | else if (x < 0) |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
483 | x = 0; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
484 | |
| 8526 | 485 | y = y + PANGO_PIXELS(pango_font_metrics_get_ascent(font_metrics) + |
| 486 | pango_font_metrics_get_descent(font_metrics)); | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
487 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
488 | 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
|
489 | gtk_window_move (GTK_WINDOW(imhtml->tip_window), x, y); |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
490 | gtk_widget_show (imhtml->tip_window); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
491 | |
| 8526 | 492 | pango_font_metrics_unref(font_metrics); |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
493 | g_object_unref(layout); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
494 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
495 | return FALSE; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
496 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
497 | |
|
11844
57ad7c52cc9c
[gaim-migrate @ 14135]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11840
diff
changeset
|
498 | static gboolean |
|
57ad7c52cc9c
[gaim-migrate @ 14135]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11840
diff
changeset
|
499 | gtk_motion_event_notify(GtkWidget *imhtml, GdkEventMotion *event, gpointer data) |
| 8061 | 500 | { |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
501 | GtkTextIter iter; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
502 | GdkWindow *win = event->window; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
503 | int x, y; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
504 | char *tip = NULL; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
505 | GSList *tags = NULL, *templist = NULL; |
| 10799 | 506 | GdkColor *norm, *pre; |
| 507 | GtkTextTag *tag = NULL, *oldprelit_tag; | |
|
18543
c590aed61aa4
Show tooltip for smileys. Fixes #1981.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18371
diff
changeset
|
508 | GtkTextChildAnchor* anchor; |
|
c590aed61aa4
Show tooltip for smileys. Fixes #1981.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18371
diff
changeset
|
509 | gboolean hand = TRUE; |
| 10799 | 510 | |
| 511 | oldprelit_tag = GTK_IMHTML(imhtml)->prelit_tag; | |
| 512 | ||
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
513 | gdk_window_get_pointer(GTK_WIDGET(imhtml)->window, NULL, NULL, NULL); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
514 | gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(imhtml), GTK_TEXT_WINDOW_WIDGET, |
| 10799 | 515 | event->x, event->y, &x, &y); |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
516 | 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
|
517 | tags = gtk_text_iter_get_tags(&iter); |
|
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 | templist = tags; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
520 | while (templist) { |
| 10799 | 521 | tag = templist->data; |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
522 | tip = g_object_get_data(G_OBJECT(tag), "link_url"); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
523 | if (tip) |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
524 | break; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
525 | templist = templist->next; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
526 | } |
| 8061 | 527 | |
| 10799 | 528 | if (tip) { |
| 529 | gtk_widget_style_get(GTK_WIDGET(imhtml), "hyperlink-prelight-color", &pre, NULL); | |
| 530 | GTK_IMHTML(imhtml)->prelit_tag = tag; | |
| 531 | if (tag != oldprelit_tag) { | |
| 532 | if (pre) | |
| 533 | g_object_set(G_OBJECT(tag), "foreground-gdk", pre, NULL); | |
| 534 | else | |
|
12253
5025434b18f8
[gaim-migrate @ 14555]
Mark Doliner <markdoliner@pidgin.im>
parents:
12230
diff
changeset
|
535 | g_object_set(G_OBJECT(tag), "foreground", "#70a0ff", NULL); |
| 10799 | 536 | } |
| 537 | } else { | |
| 538 | GTK_IMHTML(imhtml)->prelit_tag = NULL; | |
| 539 | } | |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
540 | |
|
10834
5fd1dfd395e8
[gaim-migrate @ 12505]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10826
diff
changeset
|
541 | if ((oldprelit_tag != NULL) && (GTK_IMHTML(imhtml)->prelit_tag != oldprelit_tag)) { |
| 10799 | 542 | gtk_widget_style_get(GTK_WIDGET(imhtml), "hyperlink-color", &norm, NULL); |
| 543 | if (norm) | |
| 544 | g_object_set(G_OBJECT(oldprelit_tag), "foreground-gdk", norm, NULL); | |
| 545 | else | |
| 546 | g_object_set(G_OBJECT(oldprelit_tag), "foreground", "blue", NULL); | |
| 547 | } | |
| 548 | ||
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
549 | if (GTK_IMHTML(imhtml)->tip) { |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
550 | if ((tip == GTK_IMHTML(imhtml)->tip)) { |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
551 | return FALSE; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
552 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
553 | /* 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
|
554 | if (GTK_IMHTML(imhtml)->tip_window) { |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
555 | gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
556 | GTK_IMHTML(imhtml)->tip_window = NULL; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
557 | } |
| 8061 | 558 | if (GTK_IMHTML(imhtml)->editable) |
| 559 | gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->text_cursor); | |
| 560 | else | |
| 561 | gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->arrow_cursor); | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
562 | if (GTK_IMHTML(imhtml)->tip_timer) |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
563 | g_source_remove(GTK_IMHTML(imhtml)->tip_timer); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
564 | GTK_IMHTML(imhtml)->tip_timer = 0; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
565 | } |
| 8061 | 566 | |
|
18543
c590aed61aa4
Show tooltip for smileys. Fixes #1981.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18371
diff
changeset
|
567 | /* 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
|
568 | 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
|
569 | if (anchor) { |
|
c590aed61aa4
Show tooltip for smileys. Fixes #1981.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18371
diff
changeset
|
570 | tip = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_plaintext"); |
|
c590aed61aa4
Show tooltip for smileys. Fixes #1981.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18371
diff
changeset
|
571 | hand = FALSE; |
|
c590aed61aa4
Show tooltip for smileys. Fixes #1981.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18371
diff
changeset
|
572 | } |
|
c590aed61aa4
Show tooltip for smileys. Fixes #1981.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18371
diff
changeset
|
573 | |
| 10799 | 574 | if (tip){ |
|
18543
c590aed61aa4
Show tooltip for smileys. Fixes #1981.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18371
diff
changeset
|
575 | if (!GTK_IMHTML(imhtml)->editable && hand) |
| 8061 | 576 | gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->hand_cursor); |
| 577 | GTK_IMHTML(imhtml)->tip_timer = g_timeout_add (TOOLTIP_TIMEOUT, | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
578 | gtk_imhtml_tip, imhtml); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
579 | } |
| 8061 | 580 | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
581 | GTK_IMHTML(imhtml)->tip = tip; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
582 | g_slist_free(tags); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
583 | return FALSE; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
584 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
585 | |
|
11677
89c2ab8d2ebf
[gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents:
11586
diff
changeset
|
586 | static gboolean |
|
89c2ab8d2ebf
[gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents:
11586
diff
changeset
|
587 | gtk_enter_event_notify(GtkWidget *imhtml, GdkEventCrossing *event, gpointer data) |
|
10946
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
588 | { |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
589 | if (GTK_IMHTML(imhtml)->editable) |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
590 | gdk_window_set_cursor( |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
591 | gtk_text_view_get_window(GTK_TEXT_VIEW(imhtml), |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
592 | GTK_TEXT_WINDOW_TEXT), |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
593 | GTK_IMHTML(imhtml)->text_cursor); |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
594 | else |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
595 | gdk_window_set_cursor( |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
596 | gtk_text_view_get_window(GTK_TEXT_VIEW(imhtml), |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
597 | GTK_TEXT_WINDOW_TEXT), |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
598 | GTK_IMHTML(imhtml)->arrow_cursor); |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
599 | |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
600 | /* propagate the event normally */ |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
601 | return FALSE; |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
602 | } |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
603 | |
|
11677
89c2ab8d2ebf
[gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents:
11586
diff
changeset
|
604 | static gboolean |
|
89c2ab8d2ebf
[gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents:
11586
diff
changeset
|
605 | gtk_leave_event_notify(GtkWidget *imhtml, GdkEventCrossing *event, gpointer data) |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
606 | { |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
607 | /* when leaving the widget, clear any current & pending tooltips and restore the cursor */ |
| 10799 | 608 | if (GTK_IMHTML(imhtml)->prelit_tag) { |
| 609 | GdkColor *norm; | |
| 610 | gtk_widget_style_get(GTK_WIDGET(imhtml), "hyperlink-color", &norm, NULL); | |
| 611 | if (norm) | |
| 612 | g_object_set(G_OBJECT(GTK_IMHTML(imhtml)->prelit_tag), "foreground-gdk", norm, NULL); | |
| 613 | else | |
| 614 | g_object_set(G_OBJECT(GTK_IMHTML(imhtml)->prelit_tag), "foreground", "blue", NULL); | |
| 615 | GTK_IMHTML(imhtml)->prelit_tag = NULL; | |
| 616 | } | |
| 617 | ||
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
618 | if (GTK_IMHTML(imhtml)->tip_window) { |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
619 | gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
620 | GTK_IMHTML(imhtml)->tip_window = NULL; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
621 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
622 | if (GTK_IMHTML(imhtml)->tip_timer) { |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
623 | g_source_remove(GTK_IMHTML(imhtml)->tip_timer); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
624 | GTK_IMHTML(imhtml)->tip_timer = 0; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
625 | } |
|
10946
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
626 | gdk_window_set_cursor( |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
627 | gtk_text_view_get_window(GTK_TEXT_VIEW(imhtml), |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
628 | GTK_TEXT_WINDOW_TEXT), NULL); |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
629 | |
|
8568
66907b37ce85
[gaim-migrate @ 9316]
Mark Doliner <markdoliner@pidgin.im>
parents:
8566
diff
changeset
|
630 | /* propagate the event normally */ |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
631 | return FALSE; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
632 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
633 | |
|
10844
fb5b88957742
[gaim-migrate @ 12516]
Richard Laager <rlaager@pidgin.im>
parents:
10834
diff
changeset
|
634 | #if (!GTK_CHECK_VERSION(2,2,0)) |
| 6066 | 635 | /* |
| 636 | * XXX - This should be removed eventually. | |
| 637 | * | |
| 8061 | 638 | * This function exists to work around a gross bug in GtkTextView. |
| 639 | * Basically, we short circuit ctrl+a and ctrl+end because they make | |
| 6066 | 640 | * el program go boom. |
| 641 | * | |
| 8061 | 642 | * It's supposed to be fixed in gtk2.2. You can view the bug report at |
| 6066 | 643 | * http://bugzilla.gnome.org/show_bug.cgi?id=107939 |
| 644 | */ | |
|
10849
476d68d7a435
[gaim-migrate @ 12521]
Richard Laager <rlaager@pidgin.im>
parents:
10844
diff
changeset
|
645 | static gboolean |
|
476d68d7a435
[gaim-migrate @ 12521]
Richard Laager <rlaager@pidgin.im>
parents:
10844
diff
changeset
|
646 | gtk_key_pressed_cb(GtkIMHtml *imhtml, GdkEventKey *event, gpointer data) |
| 8677 | 647 | { |
|
10844
fb5b88957742
[gaim-migrate @ 12516]
Richard Laager <rlaager@pidgin.im>
parents:
10834
diff
changeset
|
648 | if (event->state & GDK_CONTROL_MASK) { |
| 6066 | 649 | switch (event->keyval) { |
|
10844
fb5b88957742
[gaim-migrate @ 12516]
Richard Laager <rlaager@pidgin.im>
parents:
10834
diff
changeset
|
650 | case 'a': |
|
fb5b88957742
[gaim-migrate @ 12516]
Richard Laager <rlaager@pidgin.im>
parents:
10834
diff
changeset
|
651 | case GDK_Home: |
|
fb5b88957742
[gaim-migrate @ 12516]
Richard Laager <rlaager@pidgin.im>
parents:
10834
diff
changeset
|
652 | case GDK_End: |
|
fb5b88957742
[gaim-migrate @ 12516]
Richard Laager <rlaager@pidgin.im>
parents:
10834
diff
changeset
|
653 | return TRUE; |
| 6066 | 654 | } |
|
10844
fb5b88957742
[gaim-migrate @ 12516]
Richard Laager <rlaager@pidgin.im>
parents:
10834
diff
changeset
|
655 | } |
| 6066 | 656 | return FALSE; |
| 657 | } | |
|
10844
fb5b88957742
[gaim-migrate @ 12516]
Richard Laager <rlaager@pidgin.im>
parents:
10834
diff
changeset
|
658 | #endif /* !(GTK+ >= 2.2.0) */ |
| 10692 | 659 | |
| 660 | static gint | |
| 661 | gtk_imhtml_expose_event (GtkWidget *widget, | |
| 662 | GdkEventExpose *event) | |
| 663 | { | |
| 10776 | 664 | GtkTextIter start, end, cur; |
| 665 | int buf_x, buf_y; | |
| 666 | GdkRectangle visible_rect; | |
| 10777 | 667 | GdkGC *gc = gdk_gc_new(GDK_DRAWABLE(event->window)); |
| 668 | GdkColor gcolor; | |
|
10844
fb5b88957742
[gaim-migrate @ 12516]
Richard Laager <rlaager@pidgin.im>
parents:
10834
diff
changeset
|
669 | |
| 10776 | 670 | gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(widget), &visible_rect); |
| 671 | gtk_text_view_buffer_to_window_coords(GTK_TEXT_VIEW(widget), | |
| 672 | GTK_TEXT_WINDOW_TEXT, | |
| 673 | visible_rect.x, | |
| 674 | visible_rect.y, | |
| 675 | &visible_rect.x, | |
| 676 | &visible_rect.y); | |
| 677 | ||
| 678 | gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(widget), GTK_TEXT_WINDOW_TEXT, | |
| 679 | event->area.x, event->area.y, &buf_x, &buf_y); | |
| 680 | ||
| 10777 | 681 | if (GTK_IMHTML(widget)->editable || GTK_IMHTML(widget)->wbfo) { |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
682 | |
| 10777 | 683 | if (GTK_IMHTML(widget)->edit.background) { |
| 684 | gdk_color_parse(GTK_IMHTML(widget)->edit.background, &gcolor); | |
| 685 | gdk_gc_set_rgb_fg_color(gc, &gcolor); | |
| 686 | } else { | |
| 687 | gdk_gc_set_rgb_fg_color(gc, &(widget->style->base[GTK_WIDGET_STATE(widget)])); | |
| 688 | } | |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
689 | |
| 10777 | 690 | gdk_draw_rectangle(event->window, |
| 691 | gc, | |
| 692 | TRUE, | |
| 693 | visible_rect.x, visible_rect.y, visible_rect.width, visible_rect.height); | |
| 694 | gdk_gc_unref(gc); | |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
695 | |
| 10777 | 696 | if (GTK_WIDGET_CLASS (parent_class)->expose_event) |
| 697 | return (* GTK_WIDGET_CLASS (parent_class)->expose_event) | |
| 698 | (widget, event); | |
| 699 | return FALSE; | |
| 700 | ||
| 701 | } | |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
702 | |
| 10776 | 703 | gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(widget), &start, buf_x, buf_y); |
| 704 | gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(widget), &end, | |
| 705 | buf_x + event->area.width, buf_y + event->area.height); | |
| 706 | ||
| 707 | ||
| 708 | ||
| 709 | cur = start; | |
| 710 | ||
| 711 | while (gtk_text_iter_in_range(&cur, &start, &end)) { | |
| 10795 | 712 | GSList *tags = gtk_text_iter_get_tags(&cur); |
| 713 | GSList *l; | |
| 10776 | 714 | |
| 715 | for (l = tags; l; l = l->next) { | |
| 716 | GtkTextTag *tag = l->data; | |
| 717 | GdkRectangle rect; | |
| 718 | GdkRectangle tag_area; | |
| 719 | const char *color; | |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
720 | |
| 10776 | 721 | if (strncmp(tag->name, "BACKGROUND ", 11)) |
| 722 | continue; | |
| 723 | ||
| 724 | if (gtk_text_iter_ends_tag(&cur, tag)) | |
| 725 | continue; | |
| 726 | ||
| 727 | gtk_text_view_get_iter_location(GTK_TEXT_VIEW(widget), &cur, &tag_area); | |
| 728 | gtk_text_view_buffer_to_window_coords(GTK_TEXT_VIEW(widget), | |
| 729 | GTK_TEXT_WINDOW_TEXT, | |
| 730 | tag_area.x, | |
| 731 | tag_area.y, | |
| 732 | &tag_area.x, | |
| 733 | &tag_area.y); | |
| 734 | rect.x = visible_rect.x; | |
| 735 | rect.y = tag_area.y; | |
|
11768
b45e26d7a4c9
[gaim-migrate @ 14059]
Gary Kramlich <grim@reaperworld.com>
parents:
11760
diff
changeset
|
736 | rect.width = visible_rect.width; |
| 10776 | 737 | |
| 10795 | 738 | do |
| 10776 | 739 | gtk_text_iter_forward_to_tag_toggle(&cur, tag); |
| 10795 | 740 | while (!gtk_text_iter_is_end(&cur) && gtk_text_iter_begins_tag(&cur, tag)); |
| 741 | ||
| 10776 | 742 | gtk_text_view_get_iter_location(GTK_TEXT_VIEW(widget), &cur, &tag_area); |
| 743 | gtk_text_view_buffer_to_window_coords(GTK_TEXT_VIEW(widget), | |
| 744 | GTK_TEXT_WINDOW_TEXT, | |
| 745 | tag_area.x, | |
| 746 | tag_area.y, | |
| 747 | &tag_area.x, | |
| 748 | &tag_area.y); | |
| 749 | ||
| 11760 | 750 | |
| 751 | rect.height = tag_area.y + tag_area.height - rect.y | |
| 752 | + 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
|
753 | |
| 10776 | 754 | color = tag->name + 11; |
| 755 | ||
| 10857 | 756 | if (!gdk_color_parse(color, &gcolor)) { |
| 10858 | 757 | gchar tmp[8]; |
| 758 | tmp[0] = '#'; | |
| 759 | strncpy(&tmp[1], color, 7); | |
| 760 | tmp[7] = '\0'; | |
| 10857 | 761 | if (!gdk_color_parse(tmp, &gcolor)) |
| 762 | gdk_color_parse("white", &gcolor); | |
| 763 | } | |
| 10776 | 764 | gdk_gc_set_rgb_fg_color(gc, &gcolor); |
| 765 | ||
| 766 | gdk_draw_rectangle(event->window, | |
| 767 | gc, | |
| 768 | TRUE, | |
| 769 | rect.x, rect.y, rect.width, rect.height); | |
| 10795 | 770 | gtk_text_iter_backward_char(&cur); /* go back one, in case the end is the begining is the end |
| 771 | * note that above, we always moved cur ahead by at least | |
| 772 | * one character */ | |
| 10776 | 773 | break; |
| 774 | } | |
| 775 | ||
| 776 | g_slist_free(tags); | |
| 10795 | 777 | |
| 778 | /* loop until another tag begins, or no tag begins */ | |
| 779 | while (gtk_text_iter_forward_to_tag_toggle(&cur, NULL) && | |
| 780 | !gtk_text_iter_is_end(&cur) && | |
| 781 | !gtk_text_iter_begins_tag(&cur, NULL)); | |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
782 | } |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
783 | |
| 10777 | 784 | gdk_gc_unref(gc); |
| 785 | ||
| 10692 | 786 | if (GTK_WIDGET_CLASS (parent_class)->expose_event) |
| 787 | return (* GTK_WIDGET_CLASS (parent_class)->expose_event) | |
| 788 | (widget, event); | |
| 10776 | 789 | |
| 10692 | 790 | return FALSE; |
| 791 | } | |
| 792 | ||
| 793 | ||
| 8931 | 794 | static void paste_unformatted_cb(GtkMenuItem *menu, GtkIMHtml *imhtml) |
| 795 | { | |
| 796 | GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD); | |
| 797 | ||
| 798 | gtk_clipboard_request_text(clipboard, paste_plaintext_received_cb, imhtml); | |
| 799 | ||
| 800 | } | |
| 801 | ||
| 13336 | 802 | static void clear_formatting_cb(GtkMenuItem *menu, GtkIMHtml *imhtml) |
| 803 | { | |
| 804 | gtk_imhtml_clear_formatting(imhtml); | |
| 805 | } | |
| 10692 | 806 | |
| 8931 | 807 | static void hijack_menu_cb(GtkIMHtml *imhtml, GtkMenu *menu, gpointer data) |
| 808 | { | |
| 809 | GtkWidget *menuitem; | |
| 810 | ||
|
12635
5b2fbc3da55b
[gaim-migrate @ 14971]
Richard Laager <rlaager@pidgin.im>
parents:
12605
diff
changeset
|
811 | menuitem = gtk_menu_item_new_with_mnemonic(_("Paste as Plain _Text")); |
| 8931 | 812 | gtk_widget_show(menuitem); |
|
14970
fd8984ce4fda
[gaim-migrate @ 17680]
Mark Doliner <markdoliner@pidgin.im>
parents:
14863
diff
changeset
|
813 | /* |
|
fd8984ce4fda
[gaim-migrate @ 17680]
Mark Doliner <markdoliner@pidgin.im>
parents:
14863
diff
changeset
|
814 | * TODO: gtk_clipboard_wait_is_text_available() iterates the glib |
|
fd8984ce4fda
[gaim-migrate @ 17680]
Mark Doliner <markdoliner@pidgin.im>
parents:
14863
diff
changeset
|
815 | * mainloop, which tends to be a source of bugs. It would |
|
fd8984ce4fda
[gaim-migrate @ 17680]
Mark Doliner <markdoliner@pidgin.im>
parents:
14863
diff
changeset
|
816 | * be good to audit this or change it to not wait. |
|
fd8984ce4fda
[gaim-migrate @ 17680]
Mark Doliner <markdoliner@pidgin.im>
parents:
14863
diff
changeset
|
817 | */ |
| 8931 | 818 | gtk_widget_set_sensitive(menuitem, |
|
12836
837fe5d43dac
[gaim-migrate @ 15184]
Richard Laager <rlaager@pidgin.im>
parents:
12833
diff
changeset
|
819 | (imhtml->editable && |
|
837fe5d43dac
[gaim-migrate @ 15184]
Richard Laager <rlaager@pidgin.im>
parents:
12833
diff
changeset
|
820 | gtk_clipboard_wait_is_text_available( |
|
837fe5d43dac
[gaim-migrate @ 15184]
Richard Laager <rlaager@pidgin.im>
parents:
12833
diff
changeset
|
821 | gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD)))); |
| 8931 | 822 | /* put it after "Paste" */ |
| 823 | gtk_menu_shell_insert(GTK_MENU_SHELL(menu), menuitem, 3); | |
| 824 | ||
| 825 | g_signal_connect(G_OBJECT(menuitem), "activate", | |
| 826 | G_CALLBACK(paste_unformatted_cb), imhtml); | |
| 13336 | 827 | |
|
13539
8036a635a316
[gaim-migrate @ 15915]
Richard Laager <rlaager@pidgin.im>
parents:
13340
diff
changeset
|
828 | menuitem = gtk_menu_item_new_with_mnemonic(_("_Reset formatting")); |
| 13336 | 829 | gtk_widget_show(menuitem); |
|
13340
e18166659513
[gaim-migrate @ 15709]
Richard Laager <rlaager@pidgin.im>
parents:
13336
diff
changeset
|
830 | gtk_widget_set_sensitive(menuitem, imhtml->editable); |
| 13336 | 831 | /* put it after Delete */ |
| 832 | gtk_menu_shell_insert(GTK_MENU_SHELL(menu), menuitem, 5); | |
| 833 | ||
| 834 | g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(clear_formatting_cb), imhtml); | |
| 8931 | 835 | } |
| 836 | ||
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
837 | static char * |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
838 | ucs2_order(gboolean swap) |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
839 | { |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
840 | gboolean be; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
841 | |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
842 | be = G_BYTE_ORDER == G_BIG_ENDIAN; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
843 | be = swap ? be : !be; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
844 | |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
845 | if (be) |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
846 | return "UCS-2BE"; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
847 | else |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
848 | return "UCS-2LE"; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
849 | |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
850 | } |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
851 | |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
852 | /* Convert from UCS-2 to UTF-8, stripping the BOM if one is present.*/ |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
853 | static gchar * |
| 11586 | 854 | ucs2_to_utf8_with_bom_check(gchar *data, guint len) { |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
855 | char *fromcode = NULL; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
856 | GError *error = NULL; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
857 | guint16 c; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
858 | gchar *utf8_ret; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
859 | |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
860 | /* |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
861 | * Unicode Techinical Report 20 |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
862 | * ( http://www.unicode.org/unicode/reports/tr20/ ) says to treat an |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
863 | * initial 0xfeff (ZWNBSP) as a byte order indicator so that is |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
864 | * 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
|
865 | * order |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
866 | */ |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
867 | |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
868 | memcpy(&c, data, 2); |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
869 | switch (c) { |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
870 | case 0xfeff: |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
871 | case 0xfffe: |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
872 | fromcode = ucs2_order(c == 0xfeff); |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
873 | data += 2; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
874 | len -= 2; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
875 | break; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
876 | default: |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
877 | fromcode = "UCS-2"; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
878 | break; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
879 | } |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
880 | |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
881 | 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
|
882 | |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
883 | if (error) { |
| 15884 | 884 | 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
|
885 | g_error_free(error); |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
886 | } |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
887 | return utf8_ret; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
888 | } |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
889 | |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
890 | |
| 8061 | 891 | 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
|
892 | 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
|
893 | gboolean primary = (clipboard != clipboard_selection); |
| 8061 | 894 | GtkTextIter 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
|
895 | GtkTextMark *sel = NULL; |
|
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
896 | GtkTextMark *ins = NULL; |
|
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
897 | |
|
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
898 | if (primary) { |
|
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
899 | 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
|
900 | 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
|
901 | 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
|
902 | 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
|
903 | } |
| 8061 | 904 | |
| 905 | if (info == TARGET_HTML) { | |
|
15111
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
906 | char *selection; |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
907 | #ifndef _WIN32 |
| 8907 | 908 | gsize len; |
| 8061 | 909 | GString *str = g_string_new(NULL); |
| 8681 | 910 | if (primary) { |
| 911 | text = gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
| 10013 | 912 | } else |
|
17546
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
913 | text = html_clipboard; |
| 8061 | 914 | |
| 915 | /* Mozilla asks that we start our text/html with the Unicode byte order mark */ | |
| 916 | str = g_string_append_unichar(str, 0xfeff); | |
| 917 | str = g_string_append(str, text); | |
| 918 | str = g_string_append_unichar(str, 0x0000); | |
|
8148
dc970ca129c5
[gaim-migrate @ 8859]
Mohammed Sameer <msameer@users.sourceforge.net>
parents:
8128
diff
changeset
|
919 | selection = g_convert(str->str, str->len, "UCS-2", "UTF-8", NULL, &len, NULL); |
|
11143
f606fb334190
[gaim-migrate @ 13207]
Mark Doliner <markdoliner@pidgin.im>
parents:
11069
diff
changeset
|
920 | gtk_selection_data_set(selection_data, gdk_atom_intern("text/html", FALSE), 16, (const guchar *)selection, len); |
| 8061 | 921 | g_string_free(str, TRUE); |
|
15111
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
922 | #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
|
923 | selection = clipboard_html_to_win32(html_clipboard); |
|
15111
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
924 | 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
|
925 | #endif |
| 8061 | 926 | g_free(selection); |
| 927 | } else { | |
| 8681 | 928 | if (primary) { |
| 929 | text = gtk_imhtml_get_text(imhtml, &start, &end); | |
| 930 | } else | |
|
17546
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
931 | text = text_clipboard; |
| 8061 | 932 | gtk_selection_data_set_text(selection_data, text, strlen(text)); |
| 933 | } | |
| 8681 | 934 | if (primary) /* This was allocated here */ |
| 935 | g_free(text); | |
| 936 | } | |
| 8061 | 937 | |
| 938 | static void gtk_imhtml_primary_clipboard_clear(GtkClipboard *clipboard, GtkIMHtml *imhtml) | |
| 7749 | 939 | { |
| 8061 | 940 | GtkTextIter insert; |
| 941 | GtkTextIter selection_bound; | |
| 942 | ||
| 943 | gtk_text_buffer_get_iter_at_mark (imhtml->text_buffer, &insert, | |
| 944 | gtk_text_buffer_get_mark (imhtml->text_buffer, "insert")); | |
| 945 | gtk_text_buffer_get_iter_at_mark (imhtml->text_buffer, &selection_bound, | |
| 946 | gtk_text_buffer_get_mark (imhtml->text_buffer, "selection_bound")); | |
| 947 | ||
| 948 | if (!gtk_text_iter_equal (&insert, &selection_bound)) | |
| 949 | gtk_text_buffer_move_mark (imhtml->text_buffer, | |
| 950 | gtk_text_buffer_get_mark (imhtml->text_buffer, "selection_bound"), | |
| 951 | &insert); | |
| 7749 | 952 | } |
| 7742 | 953 | |
|
17546
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
954 | 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
|
955 | 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
|
956 | { |
|
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
957 | clipboard_selection = NULL; |
|
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
958 | } |
|
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
959 | |
| 8677 | 960 | static void copy_clipboard_cb(GtkIMHtml *imhtml, gpointer unused) |
| 7749 | 961 | { |
| 8681 | 962 | 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
|
963 | 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
|
964 | 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
|
965 | clipboard_selection = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD); |
|
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
966 | gtk_clipboard_set_with_owner(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
|
967 | 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
|
968 | (GtkClipboardGetFunc)gtk_imhtml_clipboard_get, |
|
17546
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
969 | (GtkClipboardClearFunc)gtk_imhtml_clipboard_clear, G_OBJECT(imhtml)); |
|
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
|
970 | |
|
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
|
971 | 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
|
972 | 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
|
973 | |
|
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
|
974 | imhtml->clipboard_html_string = gtk_imhtml_get_markup_range(imhtml, &start, &end); |
|
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
|
975 | imhtml->clipboard_text_string = 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
|
976 | |
|
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
977 | text_clipboard = imhtml->clipboard_text_string; |
|
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
978 | html_clipboard = imhtml->clipboard_html_string; |
|
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
979 | |
| 8681 | 980 | } |
| 981 | ||
| 8061 | 982 | g_signal_stop_emission_by_name(imhtml, "copy-clipboard"); |
| 983 | } | |
| 984 | ||
| 8698 | 985 | static void cut_clipboard_cb(GtkIMHtml *imhtml, gpointer unused) |
| 986 | { | |
| 987 | 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
|
988 | 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
|
989 | 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
|
990 | clipboard_selection = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD); |
|
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
991 | gtk_clipboard_set_with_owner(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
|
992 | 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
|
993 | (GtkClipboardGetFunc)gtk_imhtml_clipboard_get, |
|
17546
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
994 | (GtkClipboardClearFunc)gtk_imhtml_clipboard_clear, G_OBJECT(imhtml)); |
|
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
|
995 | |
|
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
|
996 | 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
|
997 | 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
|
998 | |
|
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
|
999 | imhtml->clipboard_html_string = gtk_imhtml_get_markup_range(imhtml, &start, &end); |
|
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
|
1000 | imhtml->clipboard_text_string = gtk_imhtml_get_text(imhtml, &start, &end); |
|
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
|
1001 | |
|
17546
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
1002 | text_clipboard = imhtml->clipboard_text_string; |
|
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
1003 | html_clipboard = imhtml->clipboard_html_string; |
|
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
1004 | |
|
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
|
1005 | 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
|
1006 | gtk_text_buffer_delete_selection(imhtml->text_buffer, FALSE, FALSE); |
| 8698 | 1007 | } |
| 1008 | ||
| 1009 | g_signal_stop_emission_by_name(imhtml, "cut-clipboard"); | |
| 1010 | } | |
| 1011 | ||
| 8931 | 1012 | static void imhtml_paste_insert(GtkIMHtml *imhtml, const char *text, gboolean plaintext) |
| 1013 | { | |
| 1014 | GtkTextIter iter; | |
| 9465 | 1015 | GtkIMHtmlOptions flags = plaintext ? 0 : (GTK_IMHTML_NO_NEWLINE | GTK_IMHTML_NO_COMMENTS); |
| 8931 | 1016 | |
| 9028 | 1017 | if (gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) |
| 1018 | gtk_text_buffer_delete_selection(imhtml->text_buffer, TRUE, TRUE); | |
| 1019 | ||
| 8931 | 1020 | gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, gtk_text_buffer_get_insert(imhtml->text_buffer)); |
| 1021 | if (!imhtml->wbfo && !plaintext) | |
| 1022 | gtk_imhtml_close_tags(imhtml, &iter); | |
| 1023 | ||
| 1024 | gtk_imhtml_insert_html_at_iter(imhtml, text, flags, &iter); | |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
1025 | gtk_text_buffer_move_mark_by_name(imhtml->text_buffer, "insert", &iter); |
| 8931 | 1026 | gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(imhtml), gtk_text_buffer_get_insert(imhtml->text_buffer), |
| 1027 | 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
|
1028 | 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
|
1029 | 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
|
1030 | |
| 8931 | 1031 | } |
| 1032 | ||
| 1033 | static void paste_plaintext_received_cb (GtkClipboard *clipboard, const gchar *text, gpointer data) | |
| 1034 | { | |
| 1035 | char *tmp; | |
| 1036 | ||
| 1037 | if (text == NULL) | |
| 1038 | return; | |
| 1039 | ||
|
10732
5e314ab498bf
[gaim-migrate @ 12334]
Richard Laager <rlaager@pidgin.im>
parents:
10699
diff
changeset
|
1040 | tmp = g_markup_escape_text(text, -1); |
| 8931 | 1041 | imhtml_paste_insert(data, tmp, TRUE); |
| 1042 | g_free(tmp); | |
| 1043 | } | |
| 1044 | ||
| 8061 | 1045 | static void paste_received_cb (GtkClipboard *clipboard, GtkSelectionData *selection_data, gpointer data) |
| 1046 | { | |
| 1047 | char *text; | |
| 1048 | GtkIMHtml *imhtml = data; | |
| 7809 | 1049 | |
|
8123
e09c75f511c2
[gaim-migrate @ 8827]
Mark Doliner <markdoliner@pidgin.im>
parents:
8120
diff
changeset
|
1050 | if (!gtk_text_view_get_editable(GTK_TEXT_VIEW(imhtml))) |
|
8105
54ea897b764e
[gaim-migrate @ 8805]
Nathan Fredrickson <nathan@silverorange.com>
parents:
8091
diff
changeset
|
1051 | return; |
|
54ea897b764e
[gaim-migrate @ 8805]
Nathan Fredrickson <nathan@silverorange.com>
parents:
8091
diff
changeset
|
1052 | |
| 8061 | 1053 | if (selection_data->length < 0) { |
| 8931 | 1054 | gtk_clipboard_request_text(clipboard, paste_plaintext_received_cb, imhtml); |
| 1055 | return; | |
| 8061 | 1056 | } else { |
| 8719 | 1057 | #if 0 |
| 1058 | /* Here's some debug code, for figuring out what sent to us over the clipboard. */ | |
| 1059 | { | |
| 1060 | int i; | |
| 1061 | ||
| 15884 | 1062 | purple_debug_misc("gtkimhtml", "In paste_received_cb():\n\tformat = %d, length = %d\n\t", |
| 8719 | 1063 | selection_data->format, selection_data->length); |
| 1064 | ||
| 1065 | for (i = 0; i < (/*(selection_data->format / 8) **/ selection_data->length); i++) { | |
| 1066 | if ((i % 70) == 0) | |
| 1067 | printf("\n\t"); | |
| 1068 | if (selection_data->data[i] == '\0') | |
| 1069 | printf("."); | |
| 1070 | else | |
| 1071 | printf("%c", selection_data->data[i]); | |
| 1072 | } | |
| 1073 | printf("\n"); | |
| 1074 | } | |
| 1075 | #endif | |
| 1076 | text = g_malloc(selection_data->length); | |
| 1077 | memcpy(text, selection_data->data, selection_data->length); | |
| 7766 | 1078 | } |
| 8061 | 1079 | |
| 8869 | 1080 | if (selection_data->length >= 2 && |
| 1081 | (*(guint16 *)text == 0xfeff || *(guint16 *)text == 0xfffe)) { | |
| 1082 | /* This is UCS-2 */ | |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
1083 | char *utf8 = ucs2_to_utf8_with_bom_check(text, selection_data->length); |
| 8061 | 1084 | g_free(text); |
| 1085 | text = utf8; | |
| 8698 | 1086 | if (!text) { |
| 15884 | 1087 | purple_debug_warning("gtkimhtml", "g_convert from UCS-2 failed in paste_received_cb\n"); |
| 8698 | 1088 | return; |
| 1089 | } | |
| 8061 | 1090 | } |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
1091 | |
| 8698 | 1092 | if (!(*text) || !g_utf8_validate(text, -1, NULL)) { |
| 15884 | 1093 | purple_debug_warning("gtkimhtml", "empty string or invalid UTF-8 in paste_received_cb\n"); |
| 8698 | 1094 | g_free(text); |
| 1095 | return; | |
| 1096 | } | |
| 1097 | ||
| 8931 | 1098 | imhtml_paste_insert(imhtml, text, FALSE); |
| 8681 | 1099 | g_free(text); |
| 8061 | 1100 | } |
| 1101 | ||
| 1102 | static void paste_clipboard_cb(GtkIMHtml *imhtml, gpointer blah) | |
| 1103 | { | |
| 8931 | 1104 | #ifdef _WIN32 |
| 1105 | /* 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
|
1106 | clipboard before we try to paste from the GTK buffer */ |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
1107 | if (!clipboard_paste_html_win32(imhtml)) { |
| 8931 | 1108 | #endif |
| 8061 | 1109 | GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD); |
| 1110 | gtk_clipboard_request_contents(clipboard, gdk_atom_intern("text/html", FALSE), | |
| 1111 | paste_received_cb, imhtml); | |
| 8931 | 1112 | #ifdef _WIN32 |
| 1113 | } | |
| 1114 | #endif | |
| 8061 | 1115 | g_signal_stop_emission_by_name(imhtml, "paste-clipboard"); |
| 7766 | 1116 | } |
| 1117 | ||
| 8677 | 1118 | static void imhtml_realized_remove_primary(GtkIMHtml *imhtml, gpointer unused) |
| 1119 | { | |
| 1120 | gtk_text_buffer_remove_selection_clipboard(GTK_IMHTML(imhtml)->text_buffer, | |
| 1121 | gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY)); | |
| 1122 | ||
| 1123 | } | |
| 1124 | ||
|
8740
098a43943bba
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
1125 | static void imhtml_destroy_add_primary(GtkIMHtml *imhtml, gpointer unused) |
|
098a43943bba
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
1126 | { |
|
098a43943bba
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
1127 | gtk_text_buffer_add_selection_clipboard(GTK_IMHTML(imhtml)->text_buffer, |
|
098a43943bba
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
1128 | gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY)); |
|
098a43943bba
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
1129 | } |
| 8677 | 1130 | |
| 1131 | static void mark_set_so_update_selection_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, GtkIMHtml *imhtml) | |
| 1132 | { | |
| 1133 | if (gtk_text_buffer_get_selection_bounds(buffer, NULL, NULL)) { | |
| 1134 | gtk_clipboard_set_with_owner(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY), | |
| 1135 | selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry), | |
| 1136 | (GtkClipboardGetFunc)gtk_imhtml_clipboard_get, | |
| 1137 | (GtkClipboardClearFunc)gtk_imhtml_primary_clipboard_clear, G_OBJECT(imhtml)); | |
| 1138 | } | |
| 1139 | } | |
| 1140 | ||
| 1141 | static gboolean gtk_imhtml_button_press_event(GtkIMHtml *imhtml, GdkEventButton *event, gpointer unused) | |
| 7346 | 1142 | { |
| 8677 | 1143 | if (event->button == 2) { |
| 1144 | int x, y; | |
| 1145 | GtkTextIter iter; | |
| 1146 | GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY); | |
| 1147 | ||
| 1148 | if (!imhtml->editable) | |
| 1149 | return FALSE; | |
| 1150 | ||
| 1151 | gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(imhtml), | |
| 1152 | GTK_TEXT_WINDOW_TEXT, | |
| 1153 | event->x, | |
| 1154 | event->y, | |
| 1155 | &x, | |
| 1156 | &y); | |
| 1157 | gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, x, y); | |
| 1158 | gtk_text_buffer_place_cursor(imhtml->text_buffer, &iter); | |
| 1159 | ||
| 1160 | gtk_clipboard_request_contents(clipboard, gdk_atom_intern("text/html", FALSE), | |
| 1161 | paste_received_cb, imhtml); | |
| 1162 | ||
| 1163 | return TRUE; | |
| 1164 | } | |
| 1165 | ||
| 7346 | 1166 | return FALSE; |
| 1167 | } | |
| 4263 | 1168 | |
|
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
|
1169 | static void |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1170 | gtk_imhtml_undo(GtkIMHtml *imhtml) { |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1171 | g_return_if_fail(GTK_IS_IMHTML(imhtml)); |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1172 | g_return_if_fail(imhtml->editable); |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1173 | |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1174 | gtk_source_undo_manager_undo(imhtml->undo_manager); |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1175 | } |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1176 | |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1177 | static void |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1178 | gtk_imhtml_redo(GtkIMHtml *imhtml) { |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1179 | g_return_if_fail(GTK_IS_IMHTML(imhtml)); |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1180 | g_return_if_fail(imhtml->editable); |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1181 | |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1182 | gtk_source_undo_manager_redo(imhtml->undo_manager); |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1183 | |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1184 | } |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1185 | |
| 10108 | 1186 | static gboolean imhtml_message_send(GtkIMHtml *imhtml) |
| 1187 | { | |
| 1188 | return FALSE; | |
| 1189 | } | |
| 1190 | ||
| 10100 | 1191 | static void imhtml_toggle_format(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons) |
| 1192 | { | |
|
10699
7f9fa4f13758
[gaim-migrate @ 12256]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10695
diff
changeset
|
1193 | /* since this function is the handler for the formatting keystrokes, |
|
7f9fa4f13758
[gaim-migrate @ 12256]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10695
diff
changeset
|
1194 | 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
|
1195 | buttons &= imhtml->format_functions; |
|
10699
7f9fa4f13758
[gaim-migrate @ 12256]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10695
diff
changeset
|
1196 | |
| 10100 | 1197 | switch (buttons) { |
| 1198 | case GTK_IMHTML_BOLD: | |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
1199 | imhtml_toggle_bold(imhtml); |
| 10100 | 1200 | break; |
| 1201 | case GTK_IMHTML_ITALIC: | |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
1202 | imhtml_toggle_italic(imhtml); |
| 10100 | 1203 | break; |
| 1204 | case GTK_IMHTML_UNDERLINE: | |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
1205 | imhtml_toggle_underline(imhtml); |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
1206 | break; |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
1207 | case GTK_IMHTML_STRIKE: |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
1208 | imhtml_toggle_strike(imhtml); |
| 10100 | 1209 | break; |
| 1210 | case GTK_IMHTML_SHRINK: | |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
1211 | imhtml_font_shrink(imhtml); |
| 10100 | 1212 | break; |
| 1213 | case GTK_IMHTML_GROW: | |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
1214 | imhtml_font_grow(imhtml); |
| 10100 | 1215 | break; |
| 1216 | default: | |
| 1217 | break; | |
| 1218 | } | |
| 1219 | } | |
| 4032 | 1220 | |
| 1221 | static void | |
| 1222 | gtk_imhtml_finalize (GObject *object) | |
| 1223 | { | |
| 1224 | GtkIMHtml *imhtml = GTK_IMHTML(object); | |
| 4895 | 1225 | GList *scalables; |
| 8962 | 1226 | GSList *l; |
| 8061 | 1227 | |
| 10798 | 1228 | if (imhtml->scroll_src) |
| 1229 | g_source_remove(imhtml->scroll_src); | |
| 1230 | if (imhtml->scroll_time) | |
| 1231 | g_timer_destroy(imhtml->scroll_time); | |
| 1232 | ||
| 4138 | 1233 | g_hash_table_destroy(imhtml->smiley_data); |
| 4032 | 1234 | gtk_smiley_tree_destroy(imhtml->default_smilies); |
| 4138 | 1235 | gdk_cursor_unref(imhtml->hand_cursor); |
| 1236 | gdk_cursor_unref(imhtml->arrow_cursor); | |
| 8061 | 1237 | gdk_cursor_unref(imhtml->text_cursor); |
| 8677 | 1238 | |
| 4735 | 1239 | if(imhtml->tip_window){ |
| 1240 | gtk_widget_destroy(imhtml->tip_window); | |
| 1241 | } | |
| 1242 | if(imhtml->tip_timer) | |
| 1243 | gtk_timeout_remove(imhtml->tip_timer); | |
| 1244 | ||
| 4895 | 1245 | for(scalables = imhtml->scalables; scalables; scalables = scalables->next) { |
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
1246 | struct scalable_data *sd = scalables->data; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
1247 | GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(sd->scalable); |
| 4895 | 1248 | scale->free(scale); |
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
1249 | g_free(sd); |
| 4895 | 1250 | } |
| 7991 | 1251 | |
| 8962 | 1252 | for (l = imhtml->im_images; l; l = l->next) { |
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
1253 | struct im_image_data *img_data = l->data; |
| 8962 | 1254 | if (imhtml->funcs->image_unref) |
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
1255 | imhtml->funcs->image_unref(img_data->id); |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
1256 | g_free(img_data); |
| 8962 | 1257 | } |
| 1258 | ||
| 4895 | 1259 | g_list_free(imhtml->scalables); |
| 8962 | 1260 | 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
|
1261 | g_queue_free(imhtml->animations); |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
1262 | g_free(imhtml->protocol_name); |
|
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
1263 | 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
|
1264 | g_object_unref(imhtml->undo_manager); |
| 4032 | 1265 | 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
|
1266 | 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
|
1267 | gtk_clipboard_set_with_owner(clipboard_selection, |
|
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
1268 | selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry), |
|
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
1269 | (GtkClipboardGetFunc)gtk_imhtml_clipboard_get, |
|
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
1270 | (GtkClipboardClearFunc)NULL, G_OBJECT(imhtml)); |
|
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
1271 | |
| 4032 | 1272 | } |
| 1428 | 1273 | |
|
10814
7e17cb56b019
[gaim-migrate @ 12468]
Luke Schierer <lschiere@pidgin.im>
parents:
10799
diff
changeset
|
1274 | /* Boring GTK+ stuff */ |
| 8519 | 1275 | static void gtk_imhtml_class_init (GtkIMHtmlClass *klass) |
| 1428 | 1276 | { |
| 9007 | 1277 | GtkWidgetClass *widget_class = (GtkWidgetClass *) klass; |
| 3922 | 1278 | GtkObjectClass *object_class; |
| 10100 | 1279 | GtkBindingSet *binding_set; |
| 4032 | 1280 | GObjectClass *gobject_class; |
| 8519 | 1281 | object_class = (GtkObjectClass*) klass; |
| 1282 | gobject_class = (GObjectClass*) klass; | |
| 4032 | 1283 | parent_class = gtk_type_class(GTK_TYPE_TEXT_VIEW); |
| 4417 | 1284 | signals[URL_CLICKED] = g_signal_new("url_clicked", |
| 1285 | G_TYPE_FROM_CLASS(gobject_class), | |
| 1286 | G_SIGNAL_RUN_FIRST, | |
| 1287 | G_STRUCT_OFFSET(GtkIMHtmlClass, url_clicked), | |
| 1288 | NULL, | |
| 1289 | 0, | |
| 1290 | g_cclosure_marshal_VOID__POINTER, | |
| 1291 | G_TYPE_NONE, 1, | |
| 1292 | G_TYPE_POINTER); | |
| 8506 | 1293 | signals[BUTTONS_UPDATE] = g_signal_new("format_buttons_update", |
| 8420 | 1294 | G_TYPE_FROM_CLASS(gobject_class), |
| 1295 | G_SIGNAL_RUN_FIRST, | |
| 1296 | G_STRUCT_OFFSET(GtkIMHtmlClass, buttons_update), | |
| 1297 | NULL, | |
| 1298 | 0, | |
|
10076
1ccc0286a4ae
[gaim-migrate @ 11057]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10062
diff
changeset
|
1299 | g_cclosure_marshal_VOID__INT, |
| 8420 | 1300 | G_TYPE_NONE, 1, |
| 1301 | G_TYPE_INT); | |
| 1302 | signals[TOGGLE_FORMAT] = g_signal_new("format_function_toggle", | |
| 1303 | G_TYPE_FROM_CLASS(gobject_class), | |
| 10100 | 1304 | G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, |
| 8420 | 1305 | G_STRUCT_OFFSET(GtkIMHtmlClass, toggle_format), |
| 1306 | NULL, | |
| 1307 | 0, | |
|
10076
1ccc0286a4ae
[gaim-migrate @ 11057]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10062
diff
changeset
|
1308 | g_cclosure_marshal_VOID__INT, |
|
1ccc0286a4ae
[gaim-migrate @ 11057]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10062
diff
changeset
|
1309 | G_TYPE_NONE, 1, |
| 8420 | 1310 | G_TYPE_INT); |
| 8427 | 1311 | signals[CLEAR_FORMAT] = g_signal_new("format_function_clear", |
| 1312 | G_TYPE_FROM_CLASS(gobject_class), | |
|
11385
38ca1438e055
[gaim-migrate @ 13612]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11315
diff
changeset
|
1313 | G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, |
| 8427 | 1314 | G_STRUCT_OFFSET(GtkIMHtmlClass, clear_format), |
| 1315 | NULL, | |
| 1316 | 0, | |
| 10100 | 1317 | g_cclosure_marshal_VOID__VOID, |
| 1318 | G_TYPE_NONE, 0); | |
| 8506 | 1319 | signals[UPDATE_FORMAT] = g_signal_new("format_function_update", |
| 10100 | 1320 | G_TYPE_FROM_CLASS(gobject_class), |
| 1321 | G_SIGNAL_RUN_FIRST, | |
| 1322 | G_STRUCT_OFFSET(GtkIMHtmlClass, update_format), | |
| 1323 | NULL, | |
| 1324 | 0, | |
| 1325 | g_cclosure_marshal_VOID__VOID, | |
| 1326 | G_TYPE_NONE, 0); | |
| 10108 | 1327 | signals[MESSAGE_SEND] = g_signal_new("message_send", |
| 1328 | G_TYPE_FROM_CLASS(gobject_class), | |
| 1329 | G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, | |
| 1330 | G_STRUCT_OFFSET(GtkIMHtmlClass, message_send), | |
| 1331 | NULL, | |
| 1332 | 0, g_cclosure_marshal_VOID__VOID, | |
| 1333 | G_TYPE_NONE, 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
|
1334 | signals [UNDO] = g_signal_new ("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
|
1335 | G_TYPE_FROM_CLASS (klass), |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1336 | G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1337 | G_STRUCT_OFFSET (GtkIMHtmlClass, 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
|
1338 | NULL, |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1339 | NULL, |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1340 | gtksourceview_marshal_VOID__VOID, |
|
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_TYPE_NONE, |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1342 | 0); |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1343 | signals [REDO] = g_signal_new ("redo", |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1344 | G_TYPE_FROM_CLASS (klass), |
|
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 | G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, |
|
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 | G_STRUCT_OFFSET (GtkIMHtmlClass, redo), |
|
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 | NULL, |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1348 | NULL, |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1349 | gtksourceview_marshal_VOID__VOID, |
|
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_TYPE_NONE, |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1351 | 0); |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1352 | |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1353 | |
| 10100 | 1354 | |
| 1355 | klass->toggle_format = imhtml_toggle_format; | |
| 10108 | 1356 | klass->message_send = imhtml_message_send; |
|
12672
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
1357 | klass->clear_format = imhtml_clear_formatting; |
|
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
|
1358 | 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
|
1359 | klass->redo = gtk_imhtml_redo; |
|
10184
543c9a84ce16
[gaim-migrate @ 11299]
Mark Doliner <markdoliner@pidgin.im>
parents:
10169
diff
changeset
|
1360 | |
| 4032 | 1361 | gobject_class->finalize = gtk_imhtml_finalize; |
|
10184
543c9a84ce16
[gaim-migrate @ 11299]
Mark Doliner <markdoliner@pidgin.im>
parents:
10169
diff
changeset
|
1362 | widget_class->drag_motion = gtk_text_view_drag_motion; |
| 10692 | 1363 | 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
|
1364 | 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
|
1365 | widget_class->size_allocate = gtk_imhtml_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
|
1366 | |
| 9007 | 1367 | gtk_widget_class_install_style_property(widget_class, g_param_spec_boxed("hyperlink-color", |
| 1368 | _("Hyperlink color"), | |
| 1369 | _("Color to draw hyperlinks."), | |
| 1370 | GDK_TYPE_COLOR, G_PARAM_READABLE)); | |
| 10799 | 1371 | gtk_widget_class_install_style_property(widget_class, g_param_spec_boxed("hyperlink-prelight-color", |
| 1372 | _("Hyperlink prelight color"), | |
| 1373 | _("Color to draw hyperlinks when mouse is over them."), | |
| 1374 | GDK_TYPE_COLOR, G_PARAM_READABLE)); | |
| 10100 | 1375 | |
| 1376 | binding_set = gtk_binding_set_by_class (parent_class); | |
| 10110 | 1377 | gtk_binding_entry_add_signal (binding_set, GDK_b, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_BOLD); |
| 10100 | 1378 | gtk_binding_entry_add_signal (binding_set, GDK_i, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_ITALIC); |
| 1379 | gtk_binding_entry_add_signal (binding_set, GDK_u, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_UNDERLINE); | |
| 1380 | gtk_binding_entry_add_signal (binding_set, GDK_plus, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_GROW); | |
| 1381 | gtk_binding_entry_add_signal (binding_set, GDK_equal, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_GROW); | |
| 1382 | gtk_binding_entry_add_signal (binding_set, GDK_minus, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_SHRINK); | |
| 10108 | 1383 | binding_set = gtk_binding_set_by_class(klass); |
|
11385
38ca1438e055
[gaim-migrate @ 13612]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11315
diff
changeset
|
1384 | gtk_binding_entry_add_signal (binding_set, GDK_r, GDK_CONTROL_MASK, "format_function_clear", 0); |
| 10108 | 1385 | gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0, "message_send", 0); |
| 1386 | gtk_binding_entry_add_signal (binding_set, GDK_Return, 0, "message_send", 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
|
1387 | gtk_binding_entry_add_signal (binding_set, GDK_z, GDK_CONTROL_MASK, "undo", 0); |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1388 | gtk_binding_entry_add_signal (binding_set, GDK_z, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "redo", 0); |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1389 | gtk_binding_entry_add_signal (binding_set, GDK_F14, 0, "undo", 0); |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1390 | |
| 1428 | 1391 | } |
| 1392 | ||
| 3922 | 1393 | static void gtk_imhtml_init (GtkIMHtml *imhtml) |
| 1428 | 1394 | { |
| 3922 | 1395 | GtkTextIter iter; |
| 1396 | 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
|
1397 | imhtml->undo_manager = gtk_source_undo_manager_new(imhtml->text_buffer); |
| 3922 | 1398 | gtk_text_buffer_get_end_iter (imhtml->text_buffer, &iter); |
| 1399 | 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
|
1400 | gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(imhtml), GTK_WRAP_WORD_CHAR); |
| 3922 | 1401 | gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(imhtml), 5); |
| 8677 | 1402 | gtk_text_view_set_left_margin(GTK_TEXT_VIEW(imhtml), 2); |
| 1403 | gtk_text_view_set_right_margin(GTK_TEXT_VIEW(imhtml), 2); | |
| 8061 | 1404 | /*gtk_text_view_set_indent(GTK_TEXT_VIEW(imhtml), -15);*/ |
| 3922 | 1405 | /*gtk_text_view_set_justification(GTK_TEXT_VIEW(imhtml), GTK_JUSTIFY_FILL);*/ |
| 8061 | 1406 | |
| 3922 | 1407 | /* These tags will be used often and can be reused--we create them on init and then apply them by name |
| 8932 | 1408 | * other tags (color, size, face, etc.) will have to be created and applied dynamically |
| 9924 | 1409 | * Note that even though we created SUB, SUP, and PRE tags here, we don't really |
| 8932 | 1410 | * apply them anywhere yet. */ |
| 3922 | 1411 | gtk_text_buffer_create_tag(imhtml->text_buffer, "BOLD", "weight", PANGO_WEIGHT_BOLD, NULL); |
| 1412 | gtk_text_buffer_create_tag(imhtml->text_buffer, "ITALICS", "style", PANGO_STYLE_ITALIC, NULL); | |
| 1413 | gtk_text_buffer_create_tag(imhtml->text_buffer, "UNDERLINE", "underline", PANGO_UNDERLINE_SINGLE, NULL); | |
| 1414 | gtk_text_buffer_create_tag(imhtml->text_buffer, "STRIKE", "strikethrough", TRUE, NULL); | |
| 1415 | gtk_text_buffer_create_tag(imhtml->text_buffer, "SUB", "rise", -5000, NULL); | |
| 1416 | gtk_text_buffer_create_tag(imhtml->text_buffer, "SUP", "rise", 5000, NULL); | |
| 1417 | gtk_text_buffer_create_tag(imhtml->text_buffer, "PRE", "family", "Monospace", NULL); | |
| 7295 | 1418 | gtk_text_buffer_create_tag(imhtml->text_buffer, "search", "background", "#22ff00", "weight", "bold", NULL); |
| 8677 | 1419 | |
| 3922 | 1420 | /* When hovering over a link, we show the hand cursor--elsewhere we show the plain ol' pointer cursor */ |
| 1421 | imhtml->hand_cursor = gdk_cursor_new (GDK_HAND2); | |
| 1422 | imhtml->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR); | |
| 8061 | 1423 | imhtml->text_cursor = gdk_cursor_new (GDK_XTERM); |
| 2993 | 1424 | |
|
6124
322206d79652
[gaim-migrate @ 6598]
Mark Doliner <markdoliner@pidgin.im>
parents:
6066
diff
changeset
|
1425 | imhtml->show_comments = TRUE; |
| 4253 | 1426 | |
| 4892 | 1427 | imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 4902 | 1428 | g_free, (GDestroyNotify)gtk_smiley_tree_destroy); |
| 4032 | 1429 | imhtml->default_smilies = gtk_smiley_tree_new(); |
| 4735 | 1430 | |
| 1431 | 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
|
1432 | 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
|
1433 | g_signal_connect(G_OBJECT(imhtml), "enter-notify-event", G_CALLBACK(gtk_enter_event_notify), NULL); |
|
10844
fb5b88957742
[gaim-migrate @ 12516]
Richard Laager <rlaager@pidgin.im>
parents:
10834
diff
changeset
|
1434 | #if (!GTK_CHECK_VERSION(2,2,0)) |
|
fb5b88957742
[gaim-migrate @ 12516]
Richard Laager <rlaager@pidgin.im>
parents:
10834
diff
changeset
|
1435 | /* See the comment for gtk_key_pressed_cb */ |
| 6066 | 1436 | g_signal_connect(G_OBJECT(imhtml), "key_press_event", G_CALLBACK(gtk_key_pressed_cb), NULL); |
|
10844
fb5b88957742
[gaim-migrate @ 12516]
Richard Laager <rlaager@pidgin.im>
parents:
10834
diff
changeset
|
1437 | #endif |
| 8677 | 1438 | g_signal_connect(G_OBJECT(imhtml), "button_press_event", G_CALLBACK(gtk_imhtml_button_press_event), NULL); |
| 1439 | 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
|
1440 | g_signal_connect(G_OBJECT(imhtml->text_buffer), "delete_range", G_CALLBACK(delete_cb), imhtml); |
| 8061 | 1441 | g_signal_connect_after(G_OBJECT(imhtml->text_buffer), "insert-text", G_CALLBACK(insert_cb), imhtml); |
| 10169 | 1442 | g_signal_connect_after(G_OBJECT(imhtml->text_buffer), "insert-child-anchor", G_CALLBACK(insert_ca_cb), imhtml); |
| 8091 | 1443 | gtk_drag_dest_set(GTK_WIDGET(imhtml), 0, |
| 1444 | link_drag_drop_targets, sizeof(link_drag_drop_targets) / sizeof(GtkTargetEntry), | |
| 1445 | GDK_ACTION_COPY); | |
| 1446 | g_signal_connect(G_OBJECT(imhtml), "drag_data_received", G_CALLBACK(gtk_imhtml_link_drag_rcv_cb), imhtml); | |
| 9300 | 1447 | g_signal_connect(G_OBJECT(imhtml), "drag_drop", G_CALLBACK(gtk_imhtml_link_drop_cb), imhtml); |
| 8091 | 1448 | |
| 7353 | 1449 | g_signal_connect(G_OBJECT(imhtml), "copy-clipboard", G_CALLBACK(copy_clipboard_cb), NULL); |
| 8698 | 1450 | g_signal_connect(G_OBJECT(imhtml), "cut-clipboard", G_CALLBACK(cut_clipboard_cb), NULL); |
| 8061 | 1451 | g_signal_connect(G_OBJECT(imhtml), "paste-clipboard", G_CALLBACK(paste_clipboard_cb), NULL); |
| 8677 | 1452 | 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
|
1453 | g_signal_connect(G_OBJECT(imhtml), "unrealize", G_CALLBACK(imhtml_destroy_add_primary), NULL); |
| 8677 | 1454 | |
| 1455 | g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set", | |
| 1456 | G_CALLBACK(mark_set_so_update_selection_cb), imhtml); | |
| 1457 | ||
|
10946
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
1458 | gtk_widget_add_events(GTK_WIDGET(imhtml), |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
1459 | GDK_LEAVE_NOTIFY_MASK | GDK_ENTER_NOTIFY_MASK); |
| 4735 | 1460 | |
| 8681 | 1461 | imhtml->clipboard_text_string = NULL; |
| 1462 | imhtml->clipboard_html_string = NULL; | |
| 1463 | ||
| 4735 | 1464 | imhtml->tip = NULL; |
| 1465 | imhtml->tip_timer = 0; | |
| 1466 | imhtml->tip_window = NULL; | |
| 4895 | 1467 | |
| 8677 | 1468 | imhtml->edit.bold = FALSE; |
| 1469 | imhtml->edit.italic = FALSE; | |
| 1470 | imhtml->edit.underline = FALSE; | |
| 8061 | 1471 | imhtml->edit.forecolor = NULL; |
| 1472 | imhtml->edit.backcolor = NULL; | |
| 1473 | imhtml->edit.fontface = NULL; | |
| 8677 | 1474 | imhtml->edit.fontsize = 0; |
| 1475 | imhtml->edit.link = NULL; | |
| 1476 | ||
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
1477 | |
| 4895 | 1478 | 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
|
1479 | imhtml->animations = g_queue_new(); |
| 8061 | 1480 | gtk_imhtml_set_editable(imhtml, FALSE); |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
1481 | g_signal_connect(G_OBJECT(imhtml), "populate-popup", |
| 8931 | 1482 | G_CALLBACK(hijack_menu_cb), NULL); |
| 2993 | 1483 | } |
| 1484 | ||
| 3922 | 1485 | GtkWidget *gtk_imhtml_new(void *a, void *b) |
| 1428 | 1486 | { |
| 4635 | 1487 | return GTK_WIDGET(g_object_new(gtk_imhtml_get_type(), NULL)); |
| 1428 | 1488 | } |
| 1489 | ||
| 9037 | 1490 | GType gtk_imhtml_get_type() |
| 1428 | 1491 | { |
| 9037 | 1492 | static GType imhtml_type = 0; |
| 1428 | 1493 | |
| 1494 | if (!imhtml_type) { | |
| 9037 | 1495 | static const GTypeInfo imhtml_info = { |
| 4635 | 1496 | sizeof(GtkIMHtmlClass), |
| 1497 | NULL, | |
| 1498 | NULL, | |
| 1499 | (GClassInitFunc) gtk_imhtml_class_init, | |
| 1500 | NULL, | |
| 1501 | NULL, | |
| 1428 | 1502 | sizeof (GtkIMHtml), |
| 4635 | 1503 | 0, |
|
12600
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
12553
diff
changeset
|
1504 | (GInstanceInitFunc) gtk_imhtml_init, |
|
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
12553
diff
changeset
|
1505 | NULL |
| 1428 | 1506 | }; |
| 4635 | 1507 | |
| 1508 | imhtml_type = g_type_register_static(gtk_text_view_get_type(), | |
| 1509 | "GtkIMHtml", &imhtml_info, 0); | |
| 1428 | 1510 | } |
| 1511 | ||
| 1512 | return imhtml_type; | |
| 1513 | } | |
| 1514 | ||
| 4417 | 1515 | struct url_data { |
| 1516 | GObject *object; | |
| 1517 | gchar *url; | |
| 1518 | }; | |
| 1519 | ||
| 8677 | 1520 | static void url_data_destroy(gpointer mydata) |
| 1521 | { | |
| 1522 | struct url_data *data = mydata; | |
| 1523 | g_object_unref(data->object); | |
| 1524 | g_free(data->url); | |
| 1525 | g_free(data); | |
| 1526 | } | |
| 1527 | ||
| 4417 | 1528 | static void url_open(GtkWidget *w, struct url_data *data) { |
| 1529 | if(!data) return; | |
| 8061 | 1530 | g_signal_emit(data->object, signals[URL_CLICKED], 0, data->url); |
| 7988 | 1531 | |
| 4417 | 1532 | } |
|
5582
2e5da5db947b
[gaim-migrate @ 5986]
Robert McQueen <robot101@debian.org>
parents:
5367
diff
changeset
|
1533 | |
| 4417 | 1534 | static void url_copy(GtkWidget *w, gchar *url) { |
| 1535 | GtkClipboard *clipboard; | |
| 1536 | ||
| 8931 | 1537 | clipboard = gtk_widget_get_clipboard(w, GDK_SELECTION_PRIMARY); |
| 4417 | 1538 | gtk_clipboard_set_text(clipboard, url, -1); |
|
5582
2e5da5db947b
[gaim-migrate @ 5986]
Robert McQueen <robot101@debian.org>
parents:
5367
diff
changeset
|
1539 | |
| 8931 | 1540 | clipboard = gtk_widget_get_clipboard(w, GDK_SELECTION_CLIPBOARD); |
|
5582
2e5da5db947b
[gaim-migrate @ 5986]
Robert McQueen <robot101@debian.org>
parents:
5367
diff
changeset
|
1541 | gtk_clipboard_set_text(clipboard, url, -1); |
| 4417 | 1542 | } |
| 1543 | ||
| 1544 | /* The callback for an event on a link tag. */ | |
|
10871
c0282a4f2250
[gaim-migrate @ 12558]
Mark Doliner <markdoliner@pidgin.im>
parents:
10865
diff
changeset
|
1545 | static gboolean tag_event(GtkTextTag *tag, GObject *imhtml, GdkEvent *event, GtkTextIter *arg2, gpointer unused) { |
| 4417 | 1546 | GdkEventButton *event_button = (GdkEventButton *) event; |
| 8061 | 1547 | if (GTK_IMHTML(imhtml)->editable) |
| 1548 | return FALSE; | |
| 3922 | 1549 | if (event->type == GDK_BUTTON_RELEASE) { |
| 8957 | 1550 | if ((event_button->button == 1) || (event_button->button == 2)) { |
| 4417 | 1551 | GtkTextIter start, end; |
| 1552 | /* we shouldn't open a URL if the user has selected something: */ | |
| 8677 | 1553 | if (gtk_text_buffer_get_selection_bounds( |
| 1554 | gtk_text_iter_get_buffer(arg2), &start, &end)) | |
| 4417 | 1555 | return FALSE; |
| 1556 | ||
| 1557 | /* A link was clicked--we emit the "url_clicked" signal | |
| 1558 | * with the URL as the argument */ | |
| 8677 | 1559 | g_object_ref(G_OBJECT(tag)); |
| 1560 | g_signal_emit(imhtml, signals[URL_CLICKED], 0, g_object_get_data(G_OBJECT(tag), "link_url")); | |
| 1561 | g_object_unref(G_OBJECT(tag)); | |
| 4417 | 1562 | return FALSE; |
| 1563 | } else if(event_button->button == 3) { | |
| 4745 | 1564 | GtkWidget *img, *item, *menu; |
| 4417 | 1565 | struct url_data *tempdata = g_new(struct url_data, 1); |
| 5091 | 1566 | tempdata->object = g_object_ref(imhtml); |
| 8677 | 1567 | tempdata->url = g_strdup(g_object_get_data(G_OBJECT(tag), "link_url")); |
| 4745 | 1568 | |
| 5091 | 1569 | /* Don't want the tooltip around if user right-clicked on link */ |
| 1570 | if (GTK_IMHTML(imhtml)->tip_window) { | |
| 1571 | gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); | |
| 1572 | GTK_IMHTML(imhtml)->tip_window = NULL; | |
| 1573 | } | |
| 1574 | if (GTK_IMHTML(imhtml)->tip_timer) { | |
| 1575 | g_source_remove(GTK_IMHTML(imhtml)->tip_timer); | |
| 1576 | GTK_IMHTML(imhtml)->tip_timer = 0; | |
| 1577 | } | |
| 8061 | 1578 | if (GTK_IMHTML(imhtml)->editable) |
| 1579 | gdk_window_set_cursor(event_button->window, GTK_IMHTML(imhtml)->text_cursor); | |
| 1580 | else | |
| 1581 | gdk_window_set_cursor(event_button->window, GTK_IMHTML(imhtml)->arrow_cursor); | |
| 4417 | 1582 | menu = gtk_menu_new(); |
| 8677 | 1583 | g_object_set_data_full(G_OBJECT(menu), "x-imhtml-url-data", tempdata, url_data_destroy); |
| 4745 | 1584 | |
| 4417 | 1585 | /* buttons and such */ |
| 1586 | ||
| 8677 | 1587 | if (!strncmp(tempdata->url, "mailto:", 7)) |
|
7140
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1588 | { |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1589 | /* Copy E-Mail Address */ |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1590 | img = gtk_image_new_from_stock(GTK_STOCK_COPY, |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1591 | GTK_ICON_SIZE_MENU); |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1592 | item = gtk_image_menu_item_new_with_mnemonic( |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1593 | _("_Copy E-Mail Address")); |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1594 | gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1595 | g_signal_connect(G_OBJECT(item), "activate", |
| 8677 | 1596 | G_CALLBACK(url_copy), tempdata->url + 7); |
|
7140
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1597 | gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1598 | } |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1599 | else |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1600 | { |
| 10936 | 1601 | /* Open Link in Browser */ |
| 1602 | img = gtk_image_new_from_stock(GTK_STOCK_JUMP_TO, | |
| 1603 | GTK_ICON_SIZE_MENU); | |
| 1604 | item = gtk_image_menu_item_new_with_mnemonic( | |
| 1605 | _("_Open Link in Browser")); | |
| 1606 | gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); | |
| 1607 | g_signal_connect(G_OBJECT(item), "activate", | |
| 1608 | G_CALLBACK(url_open), tempdata); | |
| 1609 | gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
| 1610 | ||
|
7140
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1611 | /* Copy Link Location */ |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1612 | img = gtk_image_new_from_stock(GTK_STOCK_COPY, |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1613 | GTK_ICON_SIZE_MENU); |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1614 | item = gtk_image_menu_item_new_with_mnemonic( |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1615 | _("_Copy Link Location")); |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1616 | gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1617 | g_signal_connect(G_OBJECT(item), "activate", |
| 8677 | 1618 | G_CALLBACK(url_copy), tempdata->url); |
|
7140
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1619 | gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1620 | } |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1621 | |
|
4756
ee19a87a495f
[gaim-migrate @ 5073]
Mark Doliner <markdoliner@pidgin.im>
parents:
4745
diff
changeset
|
1622 | |
| 4417 | 1623 | gtk_widget_show_all(menu); |
|
4756
ee19a87a495f
[gaim-migrate @ 5073]
Mark Doliner <markdoliner@pidgin.im>
parents:
4745
diff
changeset
|
1624 | gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, |
|
ee19a87a495f
[gaim-migrate @ 5073]
Mark Doliner <markdoliner@pidgin.im>
parents:
4745
diff
changeset
|
1625 | event_button->button, event_button->time); |
| 4745 | 1626 | |
| 4417 | 1627 | return TRUE; |
| 1628 | } | |
| 1428 | 1629 | } |
| 4417 | 1630 | if(event->type == GDK_BUTTON_PRESS && event_button->button == 3) |
| 1631 | return TRUE; /* Clicking the right mouse button on a link shouldn't | |
| 1632 | be caught by the regular GtkTextView menu */ | |
| 1633 | else | |
| 1634 | return FALSE; /* Let clicks go through if we didn't catch anything */ | |
| 1428 | 1635 | } |
| 1636 | ||
| 9300 | 1637 | static gboolean |
| 1638 | gtk_text_view_drag_motion (GtkWidget *widget, | |
| 1639 | GdkDragContext *context, | |
| 1640 | gint x, | |
| 1641 | gint y, | |
| 1642 | guint time) | |
| 1643 | { | |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
1644 | GdkDragAction suggested_action = 0; |
| 9300 | 1645 | |
|
10145
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1646 | 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
|
1647 | /* can't accept any of the offered targets */ |
| 9300 | 1648 | } else { |
| 1649 | GtkWidget *source_widget; | |
| 1650 | suggested_action = context->suggested_action; | |
| 1651 | source_widget = gtk_drag_get_source_widget (context); | |
| 1652 | if (source_widget == widget) { | |
| 1653 | /* Default to MOVE, unless the user has | |
| 1654 | * pressed ctrl or alt to affect available actions | |
| 1655 | */ | |
| 1656 | if ((context->actions & GDK_ACTION_MOVE) != 0) | |
| 1657 | suggested_action = GDK_ACTION_MOVE; | |
| 1658 | } | |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
1659 | } |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
1660 | |
|
10145
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1661 | gdk_drag_status (context, suggested_action, time); |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
1662 | |
| 9300 | 1663 | /* TRUE return means don't propagate the drag motion to parent |
| 1664 | * widgets that may also be drop sites. | |
| 1665 | */ | |
| 1666 | return TRUE; | |
| 1667 | } | |
| 1668 | ||
| 1669 | static void | |
| 1670 | gtk_imhtml_link_drop_cb(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer user_data) | |
| 1671 | { | |
| 1672 | GdkAtom target = gtk_drag_dest_find_target (widget, context, NULL); | |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
1673 | |
| 9300 | 1674 | if (target != GDK_NONE) |
| 1675 | gtk_drag_get_data (widget, context, target, time); | |
| 1676 | else | |
| 1677 | gtk_drag_finish (context, FALSE, FALSE, time); | |
| 1678 | ||
| 1679 | return; | |
| 1680 | } | |
| 1681 | ||
| 8091 | 1682 | static void |
| 1683 | 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
|
1684 | GtkSelectionData *sd, guint info, guint t, GtkIMHtml *imhtml) |
| 8091 | 1685 | { |
| 9300 | 1686 | gchar **links; |
| 1687 | gchar *link; | |
|
11143
f606fb334190
[gaim-migrate @ 13207]
Mark Doliner <markdoliner@pidgin.im>
parents:
11069
diff
changeset
|
1688 | char *text = (char *)sd->data; |
| 9300 | 1689 | GtkTextMark *mark = gtk_text_buffer_get_insert(imhtml->text_buffer); |
| 1690 | GtkTextIter iter; | |
|
10782
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1691 | gint i = 0; |
| 9300 | 1692 | |
| 1693 | gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); | |
| 1694 | ||
| 8091 | 1695 | if(gtk_imhtml_get_editable(imhtml) && sd->data){ |
| 9300 | 1696 | switch (info) { |
|
10145
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1697 | case GTK_IMHTML_DRAG_URL: |
|
11143
f606fb334190
[gaim-migrate @ 13207]
Mark Doliner <markdoliner@pidgin.im>
parents:
11069
diff
changeset
|
1698 | /* TODO: Is it really ok to change sd->data...? */ |
| 15884 | 1699 | purple_str_strip_char((char *)sd->data, '\r'); |
|
11143
f606fb334190
[gaim-migrate @ 13207]
Mark Doliner <markdoliner@pidgin.im>
parents:
11069
diff
changeset
|
1700 | |
|
f606fb334190
[gaim-migrate @ 13207]
Mark Doliner <markdoliner@pidgin.im>
parents:
11069
diff
changeset
|
1701 | links = g_strsplit((char *)sd->data, "\n", 0); |
|
10782
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1702 | while((link = links[i]) != NULL){ |
| 15884 | 1703 | if(purple_str_has_prefix(link, "http://") || |
| 1704 | purple_str_has_prefix(link, "https://") || | |
| 1705 | purple_str_has_prefix(link, "ftp://")) | |
|
10782
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1706 | { |
|
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1707 | gchar *label; |
|
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1708 | |
|
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1709 | if(links[i + 1]) |
|
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1710 | i++; |
|
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1711 | |
|
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1712 | label = links[i]; |
|
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1713 | |
|
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1714 | gtk_imhtml_insert_link(imhtml, mark, link, label); |
| 9300 | 1715 | } else if (link=='\0') { |
| 1716 | /* Ignore blank lines */ | |
| 1717 | } else { | |
| 1718 | /* 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
|
1719 | /* ... don't pretend we handled it if we didn't */ |
|
7d7f8cfa2b4f
[gaim-migrate @ 11556]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
10297
diff
changeset
|
1720 | gtk_drag_finish(dc, FALSE, FALSE, t); |
|
10782
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1721 | g_strfreev(links); |
|
10345
7d7f8cfa2b4f
[gaim-migrate @ 11556]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
10297
diff
changeset
|
1722 | return; |
| 9300 | 1723 | } |
|
10782
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1724 | |
|
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1725 | i++; |
| 8091 | 1726 | } |
|
10782
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1727 | g_strfreev(links); |
| 9300 | 1728 | break; |
|
10145
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1729 | case GTK_IMHTML_DRAG_HTML: |
|
10243
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1730 | { |
|
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1731 | char *utf8 = NULL; |
|
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1732 | /* 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
|
1733 | * as explained by this comment in gtkhtml: |
|
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1734 | * |
|
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1735 | * 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
|
1736 | * mozilla/netscape alway use ucs2 for text/html |
|
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1737 | * 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
|
1738 | * 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
|
1739 | * |
|
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1740 | * See also the comment on text/html here: |
|
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1741 | * 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
|
1742 | */ |
|
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1743 | if (sd->length >= 2 && !g_utf8_validate(text, sd->length - 1, NULL)) { |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
1744 | utf8 = ucs2_to_utf8_with_bom_check(text, sd->length); |
|
10243
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1745 | |
|
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1746 | if (!utf8) { |
| 15884 | 1747 | purple_debug_warning("gtkimhtml", "g_convert from UCS-2 failed in drag_rcv_cb\n"); |
| 9300 | 1748 | return; |
| 1749 | } | |
|
10243
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1750 | } else if (!(*text) || !g_utf8_validate(text, -1, NULL)) { |
| 15884 | 1751 | purple_debug_warning("gtkimhtml", "empty string or invalid UTF-8 in drag_rcv_cb\n"); |
| 9300 | 1752 | return; |
| 1753 | } | |
|
10243
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1754 | |
|
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1755 | 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
|
1756 | g_free(utf8); |
| 9300 | 1757 | break; |
|
10243
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1758 | } |
|
10145
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1759 | case GTK_IMHTML_DRAG_TEXT: |
|
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1760 | if (!(*text) || !g_utf8_validate(text, -1, NULL)) { |
| 15884 | 1761 | 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
|
1762 | return; |
|
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1763 | } else { |
|
10732
5e314ab498bf
[gaim-migrate @ 12334]
Richard Laager <rlaager@pidgin.im>
parents:
10699
diff
changeset
|
1764 | char *tmp = g_markup_escape_text(text, -1); |
|
10145
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1765 | gtk_imhtml_insert_html_at_iter(imhtml, tmp, 0, &iter); |
|
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1766 | g_free(tmp); |
|
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1767 | } |
|
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1768 | break; |
| 9300 | 1769 | default: |
|
10145
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1770 | gtk_drag_finish(dc, FALSE, FALSE, t); |
|
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1771 | return; |
| 8091 | 1772 | } |
| 1773 | gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t); | |
| 1774 | } else { | |
| 1775 | gtk_drag_finish(dc, FALSE, FALSE, t); | |
| 1776 | } | |
| 1777 | } | |
| 1778 | ||
| 4298 | 1779 | /* this isn't used yet |
| 9300 | 1780 | static void gtk_smiley_tree_remove (GtkSmileyTree *tree, |
| 4263 | 1781 | GtkIMHtmlSmiley *smiley) |
| 4032 | 1782 | { |
| 1783 | GtkSmileyTree *t = tree; | |
| 4263 | 1784 | const gchar *x = smiley->smile; |
| 4032 | 1785 | gint len = 0; |
| 1786 | ||
| 1787 | while (*x) { | |
| 1788 | gchar *pos; | |
| 1789 | ||
| 1790 | if (!t->values) | |
| 1791 | return; | |
| 1792 | ||
| 1793 | pos = strchr (t->values->str, *x); | |
| 1794 | if (pos) | |
| 1795 | t = t->children [(int) pos - (int) t->values->str]; | |
| 1796 | else | |
| 1797 | return; | |
| 1798 | ||
| 1799 | x++; len++; | |
| 1800 | } | |
| 1801 | ||
| 4141 | 1802 | if (t->image) { |
| 4032 | 1803 | t->image = NULL; |
| 4141 | 1804 | } |
| 4032 | 1805 | } |
| 4298 | 1806 | */ |
| 1807 | ||
| 4032 | 1808 | |
| 1809 | static gint | |
| 1810 | gtk_smiley_tree_lookup (GtkSmileyTree *tree, | |
| 1811 | const gchar *text) | |
| 1812 | { | |
| 1813 | GtkSmileyTree *t = tree; | |
| 1814 | const gchar *x = text; | |
| 1815 | gint len = 0; | |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
1816 | const gchar *amp; |
| 8505 | 1817 | gint alen; |
| 4032 | 1818 | |
| 1819 | while (*x) { | |
| 1820 | gchar *pos; | |
| 1821 | ||
| 1822 | if (!t->values) | |
| 1823 | break; | |
| 1824 | ||
| 16144 | 1825 | if(*x == '&' && (amp = purple_markup_unescape_entity(x, &alen))) { |
|
10865
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1826 | gboolean matched = TRUE; |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1827 | /* Make sure all chars of the unescaped value match */ |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1828 | while (*(amp + 1)) { |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1829 | pos = strchr (t->values->str, *amp); |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1830 | if (pos) |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1831 | 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
|
1832 | else { |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1833 | matched = FALSE; |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1834 | break; |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1835 | } |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1836 | amp++; |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1837 | } |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1838 | if (!matched) |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1839 | break; |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1840 | |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1841 | pos = strchr (t->values->str, *amp); |
| 8505 | 1842 | } |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
1843 | else if (*x == '<') /* Because we're all WYSIWYG now, a '<' |
| 9636 | 1844 | * char should only appear as the start of a tag. Perhaps a safer (but costlier) |
| 1845 | * check would be to call gtk_imhtml_is_tag on it */ | |
| 10600 | 1846 | break; |
|
10865
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1847 | else { |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1848 | alen = 1; |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1849 | pos = strchr (t->values->str, *x); |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1850 | } |
| 8505 | 1851 | |
| 4032 | 1852 | if (pos) |
| 7371 | 1853 | t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)]; |
| 4032 | 1854 | else |
| 1855 | break; | |
| 1856 | ||
|
10865
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1857 | x += alen; |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1858 | len += alen; |
| 4032 | 1859 | } |
| 1860 | ||
| 1861 | if (t->image) | |
| 1862 | return len; | |
| 1863 | ||
| 1864 | return 0; | |
| 1865 | } | |
| 1866 | ||
| 1867 | void | |
| 4263 | 1868 | gtk_imhtml_associate_smiley (GtkIMHtml *imhtml, |
|
10537
9ece7671fa62
[gaim-migrate @ 11890]
Mark Doliner <markdoliner@pidgin.im>
parents:
10526
diff
changeset
|
1869 | const gchar *sml, |
| 4263 | 1870 | GtkIMHtmlSmiley *smiley) |
| 4032 | 1871 | { |
| 1872 | GtkSmileyTree *tree; | |
| 1873 | g_return_if_fail (imhtml != NULL); | |
| 1874 | g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 7371 | 1875 | |
| 4032 | 1876 | if (sml == NULL) |
| 1877 | tree = imhtml->default_smilies; | |
|
12833
1f461f275b90
[gaim-migrate @ 15181]
Richard Laager <rlaager@pidgin.im>
parents:
12796
diff
changeset
|
1878 | else if (!(tree = g_hash_table_lookup(imhtml->smiley_data, sml))) { |
| 4032 | 1879 | tree = gtk_smiley_tree_new(); |
| 4892 | 1880 | g_hash_table_insert(imhtml->smiley_data, g_strdup(sml), tree); |
| 4032 | 1881 | } |
| 1882 | ||
| 12335 | 1883 | smiley->imhtml = imhtml; |
| 1884 | ||
| 4263 | 1885 | gtk_smiley_tree_insert (tree, smiley); |
| 4032 | 1886 | } |
| 1887 | ||
| 1888 | static gboolean | |
| 1889 | gtk_imhtml_is_smiley (GtkIMHtml *imhtml, | |
| 1890 | GSList *fonts, | |
| 1891 | const gchar *text, | |
| 1892 | gint *len) | |
| 1893 | { | |
| 1894 | GtkSmileyTree *tree; | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
1895 | GtkIMHtmlFontDetail *font; |
| 4032 | 1896 | char *sml = NULL; |
| 1897 | ||
| 1898 | if (fonts) { | |
| 1899 | font = fonts->data; | |
| 1900 | sml = font->sml; | |
| 1901 | } | |
| 1902 | ||
| 9029 | 1903 | if (!sml) |
| 1904 | sml = imhtml->protocol_name; | |
| 1905 | ||
| 1906 | if (!sml || !(tree = g_hash_table_lookup(imhtml->smiley_data, sml))) | |
| 4032 | 1907 | tree = imhtml->default_smilies; |
| 9029 | 1908 | |
| 4032 | 1909 | if (tree == NULL) |
| 1910 | return FALSE; | |
| 7371 | 1911 | |
| 8505 | 1912 | *len = gtk_smiley_tree_lookup (tree, text); |
| 4032 | 1913 | return (*len > 0); |
| 1914 | } | |
| 1915 | ||
| 10526 | 1916 | GtkIMHtmlSmiley * |
| 1917 | gtk_imhtml_smiley_get(GtkIMHtml *imhtml, | |
| 1918 | const gchar *sml, | |
| 1919 | const gchar *text) | |
| 4032 | 1920 | { |
| 1921 | GtkSmileyTree *t; | |
| 1922 | const gchar *x = text; | |
| 1923 | if (sml == NULL) | |
| 1924 | t = imhtml->default_smilies; | |
| 7371 | 1925 | else |
| 4032 | 1926 | t = g_hash_table_lookup(imhtml->smiley_data, sml); |
| 7371 | 1927 | |
| 4032 | 1928 | |
| 1929 | if (t == NULL) | |
| 10526 | 1930 | return sml ? gtk_imhtml_smiley_get(imhtml, NULL, text) : NULL; |
| 4032 | 1931 | |
| 1932 | while (*x) { | |
| 1933 | gchar *pos; | |
| 1934 | ||
| 1935 | if (!t->values) { | |
| 10526 | 1936 | return sml ? gtk_imhtml_smiley_get(imhtml, NULL, text) : NULL; |
| 4032 | 1937 | } |
| 7371 | 1938 | |
| 4032 | 1939 | pos = strchr (t->values->str, *x); |
| 1940 | if (pos) { | |
| 7371 | 1941 | t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)]; |
| 4032 | 1942 | } else { |
| 10526 | 1943 | return sml ? gtk_imhtml_smiley_get(imhtml, NULL, text) : NULL; |
| 4032 | 1944 | } |
| 1945 | x++; | |
| 1946 | } | |
| 1947 | ||
| 10526 | 1948 | return t->image; |
| 1949 | } | |
| 1950 | ||
|
11677
89c2ab8d2ebf
[gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents:
11586
diff
changeset
|
1951 | 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
|
1952 | gtk_smiley_get_image(GtkIMHtmlSmiley *smiley) |
| 10526 | 1953 | { |
| 1954 | if (!smiley->icon && smiley->file) { | |
| 1955 | smiley->icon = gdk_pixbuf_animation_new_from_file(smiley->file, NULL); | |
| 1956 | } else if (!smiley->icon && smiley->loader) { | |
| 1957 | smiley->icon = gdk_pixbuf_loader_get_animation(smiley->loader); | |
| 1958 | if (smiley->icon) | |
| 1959 | g_object_ref(G_OBJECT(smiley->icon)); | |
| 1960 | } | |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
1961 | |
| 10526 | 1962 | return smiley->icon; |
| 4032 | 1963 | } |
| 8890 | 1964 | |
|
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
|
1965 | static GdkPixbufAnimation * |
|
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
|
1966 | gtk_smiley_tree_image (GtkIMHtml *imhtml, |
|
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
|
1967 | const gchar *sml, |
|
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
|
1968 | const gchar *text) |
|
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
|
1969 | { |
|
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
|
1970 | 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
|
1971 | |
|
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
|
1972 | smiley = gtk_imhtml_smiley_get(imhtml,sml,text); |
|
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
|
1973 | |
|
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
|
1974 | if (!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
|
1975 | return NULL; |
|
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
|
1976 | |
|
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
|
1977 | return 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
|
1978 | } |
|
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
|
1979 | |
| 4793 | 1980 | #define VALID_TAG(x) if (!g_ascii_strncasecmp (string, x ">", strlen (x ">"))) { \ |
| 3922 | 1981 | *tag = g_strndup (string, strlen (x)); \ |
| 1982 | *len = strlen (x) + 1; \ | |
| 1983 | return TRUE; \ | |
| 1984 | } \ | |
| 1985 | (*type)++ | |
| 1428 | 1986 | |
| 4793 | 1987 | #define VALID_OPT_TAG(x) if (!g_ascii_strncasecmp (string, x " ", strlen (x " "))) { \ |
| 3922 | 1988 | const gchar *c = string + strlen (x " "); \ |
| 1989 | gchar e = '"'; \ | |
| 1990 | gboolean quote = FALSE; \ | |
| 1991 | while (*c) { \ | |
| 1992 | if (*c == '"' || *c == '\'') { \ | |
| 1993 | if (quote && (*c == e)) \ | |
| 1994 | quote = !quote; \ | |
| 1995 | else if (!quote) { \ | |
| 1996 | quote = !quote; \ | |
| 1997 | e = *c; \ | |
| 1998 | } \ | |
| 1999 | } else if (!quote && (*c == '>')) \ | |
| 2000 | break; \ | |
| 2001 | c++; \ | |
| 2002 | } \ | |
| 2003 | if (*c) { \ | |
| 2004 | *tag = g_strndup (string, c - string); \ | |
| 2005 | *len = c - string + 1; \ | |
| 2006 | return TRUE; \ | |
| 2007 | } \ | |
| 2008 | } \ | |
| 2009 | (*type)++ | |
| 1428 | 2010 | |
| 2011 | ||
|
1472
ce83d12b7df9
[gaim-migrate @ 1482]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1463
diff
changeset
|
2012 | static gboolean |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2013 | gtk_imhtml_is_tag (const gchar *string, |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2014 | gchar **tag, |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2015 | gint *len, |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2016 | gint *type) |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2017 | { |
| 8061 | 2018 | char *close; |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2019 | *type = 1; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2020 | |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2021 | |
| 8061 | 2022 | if (!(close = strchr (string, '>'))) |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2023 | return FALSE; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2024 | |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2025 | VALID_TAG ("B"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2026 | VALID_TAG ("BOLD"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2027 | VALID_TAG ("/B"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2028 | VALID_TAG ("/BOLD"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2029 | VALID_TAG ("I"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2030 | VALID_TAG ("ITALIC"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2031 | VALID_TAG ("/I"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2032 | VALID_TAG ("/ITALIC"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2033 | VALID_TAG ("U"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2034 | VALID_TAG ("UNDERLINE"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2035 | VALID_TAG ("/U"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2036 | VALID_TAG ("/UNDERLINE"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2037 | VALID_TAG ("S"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2038 | VALID_TAG ("STRIKE"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2039 | VALID_TAG ("/S"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2040 | VALID_TAG ("/STRIKE"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2041 | VALID_TAG ("SUB"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2042 | VALID_TAG ("/SUB"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2043 | VALID_TAG ("SUP"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2044 | VALID_TAG ("/SUP"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2045 | VALID_TAG ("PRE"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2046 | VALID_TAG ("/PRE"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2047 | VALID_TAG ("TITLE"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2048 | VALID_TAG ("/TITLE"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2049 | VALID_TAG ("BR"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2050 | VALID_TAG ("HR"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2051 | VALID_TAG ("/FONT"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2052 | VALID_TAG ("/A"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2053 | VALID_TAG ("P"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2054 | VALID_TAG ("/P"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2055 | VALID_TAG ("H3"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2056 | VALID_TAG ("/H3"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2057 | VALID_TAG ("HTML"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2058 | VALID_TAG ("/HTML"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2059 | VALID_TAG ("BODY"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2060 | VALID_TAG ("/BODY"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2061 | VALID_TAG ("FONT"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2062 | VALID_TAG ("HEAD"); |
| 2993 | 2063 | VALID_TAG ("/HEAD"); |
| 2064 | VALID_TAG ("BINARY"); | |
| 2065 | VALID_TAG ("/BINARY"); | |
| 5093 | 2066 | |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2067 | VALID_OPT_TAG ("HR"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2068 | VALID_OPT_TAG ("FONT"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2069 | VALID_OPT_TAG ("BODY"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2070 | VALID_OPT_TAG ("A"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2071 | VALID_OPT_TAG ("IMG"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2072 | VALID_OPT_TAG ("P"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2073 | VALID_OPT_TAG ("H3"); |
| 5093 | 2074 | VALID_OPT_TAG ("HTML"); |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2075 | |
| 5101 | 2076 | VALID_TAG ("CITE"); |
| 2077 | VALID_TAG ("/CITE"); | |
| 2078 | VALID_TAG ("EM"); | |
| 2079 | VALID_TAG ("/EM"); | |
| 2080 | VALID_TAG ("STRONG"); | |
| 2081 | VALID_TAG ("/STRONG"); | |
| 2082 | ||
| 5104 | 2083 | VALID_OPT_TAG ("SPAN"); |
| 2084 | VALID_TAG ("/SPAN"); | |
| 5174 | 2085 | VALID_TAG ("BR/"); /* hack until gtkimhtml handles things better */ |
|
6982
12f08de92674
[gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
6882
diff
changeset
|
2086 | VALID_TAG ("IMG"); |
| 8026 | 2087 | VALID_TAG("SPAN"); |
| 8061 | 2088 | VALID_OPT_TAG("BR"); |
| 7988 | 2089 | |
| 4793 | 2090 | if (!g_ascii_strncasecmp(string, "!--", strlen ("!--"))) { |
|
2954
fc07d855731d
[gaim-migrate @ 2967]
Christian Hammond <chipx86@chipx86.com>
parents:
2898
diff
changeset
|
2091 | gchar *e = strstr (string + strlen("!--"), "-->"); |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2092 | if (e) { |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2093 | *len = e - string + strlen ("-->"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2094 | *tag = g_strndup (string + strlen ("!--"), *len - strlen ("!---->")); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2095 | return TRUE; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2096 | } |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2097 | } |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2098 | |
| 8061 | 2099 | *type = -1; |
| 2100 | *len = close - string + 1; | |
| 2101 | *tag = g_strndup(string, *len - 1); | |
| 2102 | return TRUE; | |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2103 | } |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2104 | |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2105 | static gchar* |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2106 | gtk_imhtml_get_html_opt (gchar *tag, |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2107 | const gchar *opt) |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2108 | { |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2109 | gchar *t = tag; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2110 | gchar *e, *a; |
| 5177 | 2111 | gchar *val; |
| 2112 | gint len; | |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2113 | const gchar *c; |
| 5177 | 2114 | GString *ret; |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2115 | |
| 4793 | 2116 | while (g_ascii_strncasecmp (t, opt, strlen (opt))) { |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2117 | gboolean quote = FALSE; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2118 | if (*t == '\0') break; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2119 | while (*t && !((*t == ' ') && !quote)) { |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2120 | if (*t == '\"') |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2121 | quote = ! quote; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2122 | t++; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2123 | } |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2124 | while (*t && (*t == ' ')) t++; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2125 | } |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2126 | |
| 4793 | 2127 | if (!g_ascii_strncasecmp (t, opt, strlen (opt))) { |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2128 | t += strlen (opt); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2129 | } else { |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2130 | return NULL; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2131 | } |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2132 | |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2133 | if ((*t == '\"') || (*t == '\'')) { |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2134 | e = a = ++t; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2135 | while (*e && (*e != *(t - 1))) e++; |
| 2993 | 2136 | if (*e == '\0') { |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2137 | return NULL; |
| 5177 | 2138 | } else |
| 2139 | val = g_strndup(a, e - a); | |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2140 | } else { |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2141 | e = a = t; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2142 | while (*e && !isspace ((gint) *e)) e++; |
| 5177 | 2143 | val = g_strndup(a, e - a); |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2144 | } |
| 5177 | 2145 | |
| 2146 | ret = g_string_new(""); | |
| 2147 | e = val; | |
| 2148 | while(*e) { | |
| 16144 | 2149 | if((c = purple_markup_unescape_entity(e, &len))) { |
| 7280 | 2150 | ret = g_string_append(ret, c); |
| 5177 | 2151 | e += len; |
| 2152 | } else { | |
| 2153 | ret = g_string_append_c(ret, *e); | |
| 2154 | e++; | |
| 2155 | } | |
| 2156 | } | |
| 2157 | ||
| 2158 | g_free(val); | |
|
8568
66907b37ce85
[gaim-migrate @ 9316]
Mark Doliner <markdoliner@pidgin.im>
parents:
8566
diff
changeset
|
2159 | |
|
66907b37ce85
[gaim-migrate @ 9316]
Mark Doliner <markdoliner@pidgin.im>
parents:
8566
diff
changeset
|
2160 | return g_string_free(ret, FALSE); |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2161 | } |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2162 | |
| 8334 | 2163 | static const char *accepted_protocols[] = { |
| 2164 | "http://", | |
| 2165 | "https://", | |
| 2166 | "ftp://" | |
| 2167 | }; | |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
2168 | |
| 8334 | 2169 | static const int accepted_protocols_size = 3; |
| 2170 | ||
| 2171 | /* returns if the beginning of the text is a protocol. If it is the protocol, returns the length so | |
| 2172 | the caller knows how long the protocol string is. */ | |
|
12412
8abe3226695e
[gaim-migrate @ 14719]
Richard Laager <rlaager@pidgin.im>
parents:
12335
diff
changeset
|
2173 | static int gtk_imhtml_is_protocol(const char *text) |
| 8334 | 2174 | { |
| 2175 | gint i; | |
| 2176 | ||
| 2177 | for(i=0; i<accepted_protocols_size; i++){ | |
|
18552
810a338ef085
Use the glib strcasecmp functions everywhere, as we've had reports of
Richard Laager <rlaager@pidgin.im>
parents:
18543
diff
changeset
|
2178 | if( g_ascii_strncasecmp(text, accepted_protocols[i], strlen(accepted_protocols[i])) == 0 ){ |
| 8334 | 2179 | return strlen(accepted_protocols[i]); |
| 2180 | } | |
| 2181 | } | |
| 2182 | return 0; | |
| 2183 | } | |
| 2184 | ||
| 8677 | 2185 | /* |
| 15884 | 2186 | <KingAnt> marv: The two IM image functions in oscar are purple_odc_send_im and purple_odc_incoming |
| 8677 | 2187 | |
| 2188 | ||
| 2189 | [19:58] <Robot101> marv: images go into the imgstore, a refcounted... well.. hash. :) | |
| 2190 | [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
|
2191 | [19:59] Ro0tSiEgE robert42 RobFlynn Robot101 ross22 roz |
| 15884 | 2192 | [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 | 2193 | [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? |
| 2194 | [20:00] <KingAnt> marv: Right | |
| 2195 | [20:00] <marv> alright | |
| 2196 | ||
| 2197 | Here's my plan with IMImages. make gtk_imhtml_[append|insert]_text_with_images instead just | |
| 2198 | gtkimhtml_[append|insert]_text (hrm maybe it should be called html instead of text), add a | |
| 15884 | 2199 | function for purple to register for look up images, i.e. gtk_imhtml_set_get_img_fnc, so that |
| 8677 | 2200 | images can be looked up like that, instead of passing a GSList of them. |
| 2201 | */ | |
| 2202 | ||
| 2203 | void gtk_imhtml_append_text_with_images (GtkIMHtml *imhtml, | |
| 2204 | const gchar *text, | |
| 2205 | GtkIMHtmlOptions options, | |
| 2206 | GSList *unused) | |
| 1428 | 2207 | { |
| 8677 | 2208 | GtkTextIter iter, ins, sel; |
| 2209 | GdkRectangle rect; | |
| 2210 | int y, height, ins_offset = 0, sel_offset = 0; | |
| 2211 | gboolean fixins = FALSE, fixsel = FALSE; | |
| 2212 | ||
| 2213 | g_return_if_fail (imhtml != NULL); | |
| 2214 | g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 2215 | g_return_if_fail (text != NULL); | |
| 2216 | ||
| 2217 | ||
| 2218 | gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); | |
| 2219 | gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &ins, gtk_text_buffer_get_insert(imhtml->text_buffer)); | |
| 2220 | if (gtk_text_iter_equal(&iter, &ins) && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) { | |
| 2221 | fixins = TRUE; | |
| 2222 | ins_offset = gtk_text_iter_get_offset(&ins); | |
| 2223 | } | |
| 2224 | ||
| 2225 | gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &sel, gtk_text_buffer_get_selection_bound(imhtml->text_buffer)); | |
| 2226 | if (gtk_text_iter_equal(&iter, &sel) && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) { | |
| 2227 | fixsel = TRUE; | |
| 2228 | sel_offset = gtk_text_iter_get_offset(&sel); | |
| 2229 | } | |
| 2230 | ||
| 2231 | gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); | |
| 2232 | gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(imhtml), &iter, &y, &height); | |
| 2233 | ||
| 2234 | ||
| 2235 | if(((y + height) - (rect.y + rect.height)) > height | |
| 2236 | && gtk_text_buffer_get_char_count(imhtml->text_buffer)){ | |
| 2237 | options |= GTK_IMHTML_NO_SCROLL; | |
| 2238 | } | |
| 2239 | ||
| 2240 | gtk_imhtml_insert_html_at_iter(imhtml, text, options, &iter); | |
| 2241 | ||
| 2242 | if (fixins) { | |
| 2243 | gtk_text_buffer_get_iter_at_offset(imhtml->text_buffer, &ins, ins_offset); | |
| 2244 | gtk_text_buffer_move_mark(imhtml->text_buffer, gtk_text_buffer_get_insert(imhtml->text_buffer), &ins); | |
| 2245 | } | |
| 2246 | ||
| 2247 | if (fixsel) { | |
| 2248 | gtk_text_buffer_get_iter_at_offset(imhtml->text_buffer, &sel, sel_offset); | |
| 2249 | gtk_text_buffer_move_mark(imhtml->text_buffer, gtk_text_buffer_get_selection_bound(imhtml->text_buffer), &sel); | |
| 2250 | } | |
| 2251 | ||
| 2252 | if (!(options & GTK_IMHTML_NO_SCROLL)) { | |
| 12553 | 2253 | gtk_imhtml_scroll_to_end(imhtml, (options & GTK_IMHTML_USE_SMOOTHSCROLLING)); |
| 8677 | 2254 | } |
| 2255 | } | |
| 2256 | ||
| 11006 | 2257 | #define MAX_SCROLL_TIME 0.4 /* seconds */ |
| 2258 | #define SCROLL_DELAY 33 /* milliseconds */ | |
| 2259 | ||
| 2260 | /* | |
| 2261 | * Smoothly scroll a GtkIMHtml. | |
| 2262 | * | |
| 2263 | * @return TRUE if the window needs to be scrolled further, FALSE if we're at the bottom. | |
| 2264 | */ | |
|
10871
c0282a4f2250
[gaim-migrate @ 12558]
Mark Doliner <markdoliner@pidgin.im>
parents:
10865
diff
changeset
|
2265 | static gboolean scroll_cb(gpointer data) |
| 10798 | 2266 | { |
| 2267 | GtkIMHtml *imhtml = data; | |
| 2268 | GtkAdjustment *adj = GTK_TEXT_VIEW(imhtml)->vadjustment; | |
| 11006 | 2269 | gdouble max_val = adj->upper - adj->page_size; |
| 2270 | ||
| 2271 | g_return_val_if_fail(imhtml->scroll_time != NULL, FALSE); | |
| 2272 | ||
| 2273 | if (g_timer_elapsed(imhtml->scroll_time, NULL) > MAX_SCROLL_TIME) { | |
| 2274 | /* time's up. jump to the end and kill the timer */ | |
| 2275 | gtk_adjustment_set_value(adj, max_val); | |
| 10798 | 2276 | g_timer_destroy(imhtml->scroll_time); |
| 2277 | imhtml->scroll_time = NULL; | |
| 2278 | return FALSE; | |
| 11006 | 2279 | } |
| 2280 | ||
| 2281 | /* scroll by 1/3rd the remaining distance */ | |
| 2282 | gtk_adjustment_set_value(adj, gtk_adjustment_get_value(adj) + ((max_val - gtk_adjustment_get_value(adj)) / 3)); | |
| 2283 | return TRUE; | |
| 10798 | 2284 | } |
| 2285 | ||
| 12553 | 2286 | static gboolean smooth_scroll_idle_cb(gpointer data) |
| 10797 | 2287 | { |
| 10798 | 2288 | GtkIMHtml *imhtml = data; |
| 11006 | 2289 | imhtml->scroll_src = g_timeout_add(SCROLL_DELAY, scroll_cb, imhtml); |
| 10797 | 2290 | return FALSE; |
| 2291 | } | |
| 2292 | ||
| 12553 | 2293 | static gboolean scroll_idle_cb(gpointer data) |
| 2294 | { | |
| 2295 | GtkIMHtml *imhtml = data; | |
| 2296 | GtkAdjustment *adj = GTK_TEXT_VIEW(imhtml)->vadjustment; | |
| 2297 | if(adj) { | |
| 2298 | gtk_adjustment_set_value(adj, adj->upper - adj->page_size); | |
| 2299 | } | |
| 2300 | imhtml->scroll_src = 0; | |
| 2301 | return FALSE; | |
| 2302 | } | |
| 2303 | ||
| 2304 | void gtk_imhtml_scroll_to_end(GtkIMHtml *imhtml, gboolean smooth) | |
| 8729 | 2305 | { |
| 10798 | 2306 | if (imhtml->scroll_time) |
| 2307 | g_timer_destroy(imhtml->scroll_time); | |
| 2308 | if (imhtml->scroll_src) | |
| 2309 | g_source_remove(imhtml->scroll_src); | |
| 12553 | 2310 | if(smooth) { |
| 2311 | imhtml->scroll_time = g_timer_new(); | |
| 2312 | imhtml->scroll_src = g_idle_add_full(G_PRIORITY_LOW, smooth_scroll_idle_cb, imhtml, NULL); | |
| 2313 | } else { | |
| 2314 | imhtml->scroll_time = NULL; | |
| 2315 | imhtml->scroll_src = g_idle_add_full(G_PRIORITY_LOW, scroll_idle_cb, imhtml, NULL); | |
| 2316 | } | |
| 8729 | 2317 | } |
| 2318 | ||
| 8677 | 2319 | void gtk_imhtml_insert_html_at_iter(GtkIMHtml *imhtml, |
| 2320 | const gchar *text, | |
| 2321 | GtkIMHtmlOptions options, | |
| 2322 | GtkTextIter *iter) | |
| 2323 | { | |
| 8061 | 2324 | GdkRectangle rect; |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2325 | gint pos = 0; |
| 3922 | 2326 | gchar *ws; |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2327 | gchar *tag; |
| 3922 | 2328 | gchar *bg = NULL; |
|
6982
12f08de92674
[gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
6882
diff
changeset
|
2329 | gint len; |
| 4032 | 2330 | gint tlen, smilelen, wpos=0; |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2331 | gint type; |
| 3922 | 2332 | const gchar *c; |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2333 | const gchar *amp; |
| 8334 | 2334 | gint len_protocol; |
| 15379 | 2335 | |
| 1428 | 2336 | guint bold = 0, |
| 2337 | italics = 0, | |
| 2338 | underline = 0, | |
| 2339 | strike = 0, | |
| 2340 | sub = 0, | |
| 2341 | sup = 0, | |
|
1691
c8bd41036372
[gaim-migrate @ 1701]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1647
diff
changeset
|
2342 | title = 0, |
| 8061 | 2343 | pre = 0; |
| 1428 | 2344 | |
| 10217 | 2345 | gboolean br = FALSE; |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2346 | gboolean align_right = FALSE; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2347 | gboolean rtl_direction = FALSE; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2348 | gint align_line = 0; |
| 15420 | 2349 | |
| 3922 | 2350 | GSList *fonts = NULL; |
| 8506 | 2351 | GObject *object; |
| 8061 | 2352 | GtkIMHtmlScalable *scalable = NULL; |
| 8677 | 2353 | |
| 2354 | g_return_if_fail (imhtml != NULL); | |
| 2355 | g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 2356 | g_return_if_fail (text != NULL); | |
| 3922 | 2357 | c = text; |
|
6982
12f08de92674
[gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
6882
diff
changeset
|
2358 | len = strlen(text); |
| 3922 | 2359 | ws = g_malloc(len + 1); |
| 2360 | ws[0] = 0; | |
| 1428 | 2361 | |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2362 | while (pos < len) { |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2363 | if (*c == '<' && gtk_imhtml_is_tag (c + 1, &tag, &tlen, &type)) { |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2364 | c++; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2365 | pos++; |
| 8061 | 2366 | ws[wpos] = '\0'; |
| 10217 | 2367 | br = FALSE; |
| 8061 | 2368 | switch (type) |
| 3922 | 2369 | { |
| 2370 | case 1: /* B */ | |
| 2371 | case 2: /* BOLD */ | |
| 5101 | 2372 | case 54: /* STRONG */ |
|
11485
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2373 | if (!(options & GTK_IMHTML_NO_FORMATTING)) { |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2374 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2375 | |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2376 | if ((bold == 0) && (imhtml->format_functions & GTK_IMHTML_BOLD)) |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2377 | gtk_imhtml_toggle_bold(imhtml); |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2378 | bold++; |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2379 | ws[0] = '\0'; wpos = 0; |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2380 | } |
| 3922 | 2381 | break; |
| 2382 | case 3: /* /B */ | |
| 2383 | case 4: /* /BOLD */ | |
| 5101 | 2384 | case 55: /* /STRONG */ |
|
11485
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2385 | if (!(options & GTK_IMHTML_NO_FORMATTING)) { |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2386 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2387 | ws[0] = '\0'; wpos = 0; |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2388 | |
|
14010
a47143a57c82
[gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents:
13552
diff
changeset
|
2389 | if (bold) { |
|
11485
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2390 | bold--; |
|
14010
a47143a57c82
[gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents:
13552
diff
changeset
|
2391 | if ((bold == 0) && (imhtml->format_functions & GTK_IMHTML_BOLD) && !imhtml->wbfo) |
|
a47143a57c82
[gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents:
13552
diff
changeset
|
2392 | gtk_imhtml_toggle_bold(imhtml); |
|
a47143a57c82
[gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents:
13552
diff
changeset
|
2393 | } |
|
11485
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2394 | } |
| 3922 | 2395 | break; |
| 2396 | case 5: /* I */ | |
| 2397 | case 6: /* ITALIC */ | |
| 5101 | 2398 | case 52: /* EM */ |
|
11485
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2399 | if (!(options & GTK_IMHTML_NO_FORMATTING)) { |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2400 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2401 | ws[0] = '\0'; wpos = 0; |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2402 | if ((italics == 0) && (imhtml->format_functions & GTK_IMHTML_ITALIC)) |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2403 | gtk_imhtml_toggle_italic(imhtml); |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2404 | italics++; |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2405 | } |
| 3922 | 2406 | break; |
| 2407 | case 7: /* /I */ | |
| 2408 | case 8: /* /ITALIC */ | |
| 5101 | 2409 | case 53: /* /EM */ |
|
11485
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2410 | if (!(options & GTK_IMHTML_NO_FORMATTING)) { |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2411 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2412 | ws[0] = '\0'; wpos = 0; |
|
14010
a47143a57c82
[gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents:
13552
diff
changeset
|
2413 | if (italics) { |
|
11485
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2414 | italics--; |
|
14010
a47143a57c82
[gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents:
13552
diff
changeset
|
2415 | if ((italics == 0) && (imhtml->format_functions & GTK_IMHTML_ITALIC) && !imhtml->wbfo) |
|
a47143a57c82
[gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents:
13552
diff
changeset
|
2416 | gtk_imhtml_toggle_italic(imhtml); |
|
a47143a57c82
[gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents:
13552
diff
changeset
|
2417 | } |
|
11485
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2418 | } |
| 3922 | 2419 | break; |
| 2420 | case 9: /* U */ | |
| 2421 | case 10: /* UNDERLINE */ | |
|
11485
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2422 | if (!(options & GTK_IMHTML_NO_FORMATTING)) { |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2423 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2424 | ws[0] = '\0'; wpos = 0; |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2425 | if ((underline == 0) && (imhtml->format_functions & GTK_IMHTML_UNDERLINE)) |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2426 | gtk_imhtml_toggle_underline(imhtml); |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2427 | underline++; |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2428 | } |
| 3922 | 2429 | break; |
| 2430 | case 11: /* /U */ | |
| 2431 | case 12: /* /UNDERLINE */ | |
|
11485
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2432 | if (!(options & GTK_IMHTML_NO_FORMATTING)) { |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2433 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2434 | ws[0] = '\0'; wpos = 0; |
|
14010
a47143a57c82
[gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents:
13552
diff
changeset
|
2435 | if (underline) { |
|
11485
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2436 | underline--; |
|
14010
a47143a57c82
[gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents:
13552
diff
changeset
|
2437 | if ((underline == 0) && (imhtml->format_functions & GTK_IMHTML_UNDERLINE) && !imhtml->wbfo) |
|
a47143a57c82
[gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents:
13552
diff
changeset
|
2438 | gtk_imhtml_toggle_underline(imhtml); |
|
a47143a57c82
[gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents:
13552
diff
changeset
|
2439 | } |
|
11485
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2440 | } |
| 3922 | 2441 | break; |
| 2442 | case 13: /* S */ | |
| 2443 | case 14: /* STRIKE */ | |
| 9924 | 2444 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 2445 | ws[0] = '\0'; wpos = 0; | |
| 2446 | if ((strike == 0) && (imhtml->format_functions & GTK_IMHTML_STRIKE)) | |
| 2447 | gtk_imhtml_toggle_strike(imhtml); | |
| 3922 | 2448 | strike++; |
| 2449 | break; | |
| 2450 | case 15: /* /S */ | |
| 2451 | case 16: /* /STRIKE */ | |
| 9924 | 2452 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 2453 | ws[0] = '\0'; wpos = 0; | |
| 3922 | 2454 | if (strike) |
| 2455 | strike--; | |
| 9924 | 2456 | if ((strike == 0) && (imhtml->format_functions & GTK_IMHTML_STRIKE) && !imhtml->wbfo) |
| 2457 | gtk_imhtml_toggle_strike(imhtml); | |
| 3922 | 2458 | break; |
| 2459 | case 17: /* SUB */ | |
| 8677 | 2460 | /* FIXME: reimpliment this */ |
| 3922 | 2461 | sub++; |
| 2462 | break; | |
| 2463 | case 18: /* /SUB */ | |
| 8677 | 2464 | /* FIXME: reimpliment this */ |
| 3922 | 2465 | if (sub) |
| 2466 | sub--; | |
| 2467 | break; | |
| 2468 | case 19: /* SUP */ | |
| 8677 | 2469 | /* FIXME: reimplement this */ |
| 3922 | 2470 | sup++; |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2471 | break; |
| 3922 | 2472 | case 20: /* /SUP */ |
| 8677 | 2473 | /* FIXME: reimplement this */ |
| 3922 | 2474 | if (sup) |
| 2475 | sup--; | |
| 2476 | break; | |
| 2477 | case 21: /* PRE */ | |
| 8677 | 2478 | /* FIXME: reimplement this */ |
| 3922 | 2479 | pre++; |
| 2480 | break; | |
| 2481 | case 22: /* /PRE */ | |
| 8677 | 2482 | /* FIXME: reimplement this */ |
| 3922 | 2483 | if (pre) |
| 2484 | pre--; | |
| 2485 | break; | |
| 2486 | case 23: /* TITLE */ | |
| 8677 | 2487 | /* FIXME: what was this supposed to do anyway? */ |
| 3922 | 2488 | title++; |
| 2489 | break; | |
| 2490 | case 24: /* /TITLE */ | |
| 8677 | 2491 | /* FIXME: make this undo whatever 23 was supposed to do */ |
| 3922 | 2492 | if (title) { |
| 2493 | if (options & GTK_IMHTML_NO_TITLE) { | |
| 2494 | wpos = 0; | |
| 2495 | ws [wpos] = '\0'; | |
| 2496 | } | |
| 2497 | title--; | |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2498 | } |
| 3922 | 2499 | break; |
| 2500 | case 25: /* BR */ | |
| 5174 | 2501 | case 58: /* BR/ */ |
| 8061 | 2502 | case 61: /* BR (opt) */ |
| 3922 | 2503 | ws[wpos] = '\n'; |
| 2504 | wpos++; | |
| 10217 | 2505 | br = TRUE; |
|
6982
12f08de92674
[gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
6882
diff
changeset
|
2506 | break; |
| 3922 | 2507 | case 26: /* HR */ |
| 2508 | case 42: /* HR (opt) */ | |
| 8726 | 2509 | { |
| 2510 | int minus; | |
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
2511 | struct scalable_data *sd = g_new(struct scalable_data, 1); |
| 8726 | 2512 | |
| 3922 | 2513 | ws[wpos++] = '\n'; |
| 8677 | 2514 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 2515 | ||
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
2516 | sd->scalable = scalable = gtk_imhtml_hr_new(); |
|
11233
28c0f184a2d4
[gaim-migrate @ 13373]
Daniel Atallah <datallah@pidgin.im>
parents:
11224
diff
changeset
|
2517 | sd->mark = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, iter, TRUE); |
| 8061 | 2518 | gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); |
| 8677 | 2519 | scalable->add_to(scalable, imhtml, iter); |
| 8726 | 2520 | minus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(imhtml)) + |
| 2521 | gtk_text_view_get_right_margin(GTK_TEXT_VIEW(imhtml)); | |
| 2522 | scalable->scale(scalable, rect.width - minus, rect.height); | |
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
2523 | imhtml->scalables = g_list_append(imhtml->scalables, sd); |
| 8061 | 2524 | ws[0] = '\0'; wpos = 0; |
| 7942 | 2525 | ws[wpos++] = '\n'; |
| 8061 | 2526 | |
| 3922 | 2527 | break; |
| 8726 | 2528 | } |
| 3922 | 2529 | case 27: /* /FONT */ |
| 8677 | 2530 | if (fonts && !imhtml->wbfo) { |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
2531 | GtkIMHtmlFontDetail *font = fonts->data; |
| 8677 | 2532 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 2533 | ws[0] = '\0'; wpos = 0; |
|
8177
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
2534 | /* NEW_BIT (NEW_TEXT_BIT); */ |
| 8677 | 2535 | |
| 8698 | 2536 | if (font->face && (imhtml->format_functions & GTK_IMHTML_FACE)) { |
| 8061 | 2537 | gtk_imhtml_toggle_fontface(imhtml, NULL); |
| 2538 | } | |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2539 | g_free (font->face); |
| 8698 | 2540 | if (font->fore && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) { |
| 8061 | 2541 | gtk_imhtml_toggle_forecolor(imhtml, NULL); |
| 2542 | } | |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2543 | g_free (font->fore); |
| 8698 | 2544 | if (font->back && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) { |
| 8061 | 2545 | gtk_imhtml_toggle_backcolor(imhtml, NULL); |
| 2546 | } | |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2547 | g_free (font->back); |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2548 | g_free (font->sml); |
| 8309 | 2549 | |
| 8698 | 2550 | if ((font->size != 3) && (imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) |
| 8309 | 2551 | gtk_imhtml_font_set_size(imhtml, 3); |
| 2552 | ||
| 10761 | 2553 | fonts = g_slist_remove (fonts, font); |
| 9245 | 2554 | g_free(font); |
| 2555 | ||
| 8309 | 2556 | if (fonts) { |
| 2557 | GtkIMHtmlFontDetail *font = fonts->data; | |
| 8677 | 2558 | |
| 8698 | 2559 | if (font->face && (imhtml->format_functions & GTK_IMHTML_FACE)) |
| 8309 | 2560 | gtk_imhtml_toggle_fontface(imhtml, font->face); |
| 8698 | 2561 | if (font->fore && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) |
| 8309 | 2562 | gtk_imhtml_toggle_forecolor(imhtml, font->fore); |
| 8698 | 2563 | if (font->back && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) |
| 8309 | 2564 | gtk_imhtml_toggle_backcolor(imhtml, font->back); |
| 8698 | 2565 | if ((font->size != 3) && (imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) |
| 8309 | 2566 | gtk_imhtml_font_set_size(imhtml, font->size); |
| 2567 | } | |
| 3922 | 2568 | } |
| 8309 | 2569 | break; |
| 3922 | 2570 | case 28: /* /A */ |
| 8677 | 2571 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 2572 | gtk_imhtml_toggle_link(imhtml, NULL); | |
| 2573 | ws[0] = '\0'; wpos = 0; | |
| 8061 | 2574 | break; |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2575 | |
| 3922 | 2576 | case 29: /* P */ |
| 2577 | case 30: /* /P */ | |
| 2578 | case 31: /* H3 */ | |
| 2579 | case 32: /* /H3 */ | |
| 2580 | case 33: /* HTML */ | |
| 2581 | case 34: /* /HTML */ | |
| 2582 | case 35: /* BODY */ | |
| 10776 | 2583 | break; |
| 3922 | 2584 | case 36: /* /BODY */ |
| 10786 | 2585 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 2586 | ws[0] = '\0'; wpos = 0; | |
| 10776 | 2587 | gtk_imhtml_toggle_background(imhtml, NULL); |
| 2588 | break; | |
| 3922 | 2589 | case 37: /* FONT */ |
| 2590 | case 38: /* HEAD */ | |
| 2591 | case 39: /* /HEAD */ | |
|
6982
12f08de92674
[gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
6882
diff
changeset
|
2592 | case 40: /* BINARY */ |
|
12f08de92674
[gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
6882
diff
changeset
|
2593 | case 41: /* /BINARY */ |
| 3922 | 2594 | break; |
| 2595 | case 43: /* FONT (opt) */ | |
| 2596 | { | |
| 4032 | 2597 | gchar *color, *back, *face, *size, *sml; |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
2598 | GtkIMHtmlFontDetail *font, *oldfont = NULL; |
| 3922 | 2599 | color = gtk_imhtml_get_html_opt (tag, "COLOR="); |
| 2600 | back = gtk_imhtml_get_html_opt (tag, "BACK="); | |
| 2601 | face = gtk_imhtml_get_html_opt (tag, "FACE="); | |
| 2602 | size = gtk_imhtml_get_html_opt (tag, "SIZE="); | |
| 4032 | 2603 | sml = gtk_imhtml_get_html_opt (tag, "SML="); |
| 2604 | if (!(color || back || face || size || sml)) | |
| 3922 | 2605 | break; |
| 8061 | 2606 | |
| 8677 | 2607 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 2608 | ws[0] = '\0'; wpos = 0; |
| 2609 | ||
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
2610 | font = g_new0 (GtkIMHtmlFontDetail, 1); |
| 3922 | 2611 | if (fonts) |
| 2612 | oldfont = fonts->data; | |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2613 | |
| 8677 | 2614 | if (color && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) { |
| 3922 | 2615 | font->fore = color; |
| 8061 | 2616 | gtk_imhtml_toggle_forecolor(imhtml, font->fore); |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2617 | } else |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2618 | g_free(color); |
| 8677 | 2619 | |
| 2620 | if (back && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) { | |
| 3922 | 2621 | font->back = back; |
| 8061 | 2622 | gtk_imhtml_toggle_backcolor(imhtml, font->back); |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2623 | } else |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2624 | g_free(back); |
| 8677 | 2625 | |
| 2626 | if (face && !(options & GTK_IMHTML_NO_FONTS) && (imhtml->format_functions & GTK_IMHTML_FACE)) { | |
| 3922 | 2627 | font->face = face; |
| 8061 | 2628 | gtk_imhtml_toggle_fontface(imhtml, font->face); |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2629 | } else |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2630 | g_free(face); |
| 4032 | 2631 | |
| 2632 | if (sml) | |
| 2633 | font->sml = sml; | |
| 2634 | else if (oldfont && oldfont->sml) | |
| 2635 | font->sml = g_strdup(oldfont->sml); | |
| 2636 | ||
| 8677 | 2637 | if (size && !(options & GTK_IMHTML_NO_SIZES) && (imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) { |
| 3922 | 2638 | if (*size == '+') { |
| 2639 | sscanf (size + 1, "%hd", &font->size); | |
| 2640 | font->size += 3; | |
| 2641 | } else if (*size == '-') { | |
| 2642 | sscanf (size + 1, "%hd", &font->size); | |
| 2643 | font->size = MAX (0, 3 - font->size); | |
| 2644 | } else if (isdigit (*size)) { | |
| 2645 | sscanf (size, "%hd", &font->size); | |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2646 | } |
|
6042
e329fe962c9a
[gaim-migrate @ 6492]
Mark Doliner <markdoliner@pidgin.im>
parents:
5967
diff
changeset
|
2647 | if (font->size > 100) |
|
e329fe962c9a
[gaim-migrate @ 6492]
Mark Doliner <markdoliner@pidgin.im>
parents:
5967
diff
changeset
|
2648 | font->size = 100; |
| 3922 | 2649 | } else if (oldfont) |
| 2650 | font->size = oldfont->size; | |
| 8309 | 2651 | else |
| 2652 | font->size = 3; | |
| 8698 | 2653 | if ((imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) |
| 2654 | gtk_imhtml_font_set_size(imhtml, font->size); | |
| 3922 | 2655 | g_free(size); |
| 2656 | fonts = g_slist_prepend (fonts, font); | |
| 2657 | } | |
| 2658 | break; | |
| 2659 | case 44: /* BODY (opt) */ | |
| 2660 | if (!(options & GTK_IMHTML_NO_COLOURS)) { | |
| 2661 | char *bgcolor = gtk_imhtml_get_html_opt (tag, "BGCOLOR="); | |
| 8677 | 2662 | if (bgcolor && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) { |
| 2663 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
| 8061 | 2664 | ws[0] = '\0'; wpos = 0; |
|
8177
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
2665 | /* NEW_BIT(NEW_TEXT_BIT); */ |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
2666 | g_free(bg); |
| 3922 | 2667 | bg = bgcolor; |
| 10776 | 2668 | gtk_imhtml_toggle_background(imhtml, bg); |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2669 | } else |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2670 | g_free(bgcolor); |
| 1428 | 2671 | } |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2672 | break; |
| 3922 | 2673 | case 45: /* A (opt) */ |
| 2674 | { | |
| 2675 | gchar *href = gtk_imhtml_get_html_opt (tag, "HREF="); | |
| 8677 | 2676 | if (href && (imhtml->format_functions & GTK_IMHTML_LINK)) { |
| 2677 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
| 8061 | 2678 | ws[0] = '\0'; wpos = 0; |
| 8677 | 2679 | gtk_imhtml_toggle_link(imhtml, href); |
| 3922 | 2680 | } |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
2681 | g_free(href); |
| 2993 | 2682 | } |
| 3922 | 2683 | break; |
| 4895 | 2684 | case 46: /* IMG (opt) */ |
|
6982
12f08de92674
[gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
6882
diff
changeset
|
2685 | case 59: /* IMG */ |
| 4895 | 2686 | { |
| 8962 | 2687 | const char *id; |
| 2688 | ||
| 2689 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
| 2690 | ws[0] = '\0'; wpos = 0; | |
| 4895 | 2691 | |
| 8677 | 2692 | if (!(imhtml->format_functions & GTK_IMHTML_IMAGE)) |
| 2693 | break; | |
| 2694 | ||
| 8962 | 2695 | id = gtk_imhtml_get_html_opt(tag, "ID="); |
| 9186 | 2696 | if (!id) |
| 2697 | break; | |
| 8962 | 2698 | gtk_imhtml_insert_image_at_iter(imhtml, atoi(id), iter); |
| 2699 | break; | |
| 4895 | 2700 | } |
| 3922 | 2701 | case 47: /* P (opt) */ |
| 2702 | case 48: /* H3 (opt) */ | |
| 5093 | 2703 | case 49: /* HTML (opt) */ |
| 5101 | 2704 | case 50: /* CITE */ |
| 2705 | case 51: /* /CITE */ | |
| 8026 | 2706 | case 56: /* SPAN (opt) */ |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2707 | /* Inline CSS Support - Douglas Thrift |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2708 | * |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2709 | * color |
| 8686 | 2710 | * background |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2711 | * font-family |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2712 | * font-size |
| 8686 | 2713 | * text-decoration: underline |
| 14395 | 2714 | * font-weight: bold |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2715 | * direction: rtl |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2716 | * text-align: right |
| 10483 | 2717 | * |
| 2718 | * TODO: | |
| 2719 | * background-color | |
| 2720 | * font-style | |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2721 | */ |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2722 | { |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2723 | gchar *style, *color, *background, *family, *size, *direction, *alignment; |
| 14395 | 2724 | gchar *textdec, *weight; |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2725 | GtkIMHtmlFontDetail *font, *oldfont = NULL; |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2726 | style = gtk_imhtml_get_html_opt (tag, "style="); |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2727 | |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2728 | if (!style) break; |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2729 | |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2730 | color = purple_markup_get_css_property (style, "color"); |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2731 | background = purple_markup_get_css_property (style, "background"); |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2732 | 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
|
2733 | 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
|
2734 | 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
|
2735 | 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
|
2736 | direction = purple_markup_get_css_property (style, "direction"); |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2737 | 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
|
2738 | |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2739 | |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2740 | if (!(color || family || size || background || textdec || weight || direction || alignment)) { |
| 8120 | 2741 | g_free(style); |
| 2742 | break; | |
| 2743 | } | |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2744 | |
| 8677 | 2745 | |
| 2746 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2747 | ws[0] = '\0'; wpos = 0; |
|
8177
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
2748 | /* NEW_BIT (NEW_TEXT_BIT); */ |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2749 | |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2750 | /* 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
|
2751 | 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
|
2752 | rtl_direction = TRUE; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2753 | /* insert RLE character to set direction */ |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2754 | ws[wpos++] = 0xE2; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2755 | ws[wpos++] = 0x80; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2756 | ws[wpos++] = 0xAB; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2757 | ws[wpos] = '\0'; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2758 | 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
|
2759 | ws[0] = '\0'; wpos = 0; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2760 | } |
| 16144 | 2761 | g_free(direction); |
| 2762 | ||
|
18552
810a338ef085
Use the glib strcasecmp functions everywhere, as we've had reports of
Richard Laager <rlaager@pidgin.im>
parents:
18543
diff
changeset
|
2763 | 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
|
2764 | align_right = TRUE; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2765 | align_line = gtk_text_iter_get_line(iter); |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2766 | } |
| 16144 | 2767 | g_free(alignment); |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2768 | |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2769 | font = g_new0 (GtkIMHtmlFontDetail, 1); |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2770 | if (fonts) |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2771 | oldfont = fonts->data; |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2772 | |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2773 | if (color && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) { |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2774 | font->fore = color; |
| 8686 | 2775 | gtk_imhtml_toggle_forecolor(imhtml, font->fore); |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2776 | } else { |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2777 | if (oldfont && oldfont->fore) |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2778 | font->fore = g_strdup(oldfont->fore); |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2779 | g_free(color); |
| 8686 | 2780 | } |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2781 | |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2782 | if (background && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) { |
| 8686 | 2783 | font->back = background; |
| 2784 | gtk_imhtml_toggle_backcolor(imhtml, font->back); | |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2785 | } else { |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2786 | if (oldfont && oldfont->back) |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2787 | font->back = g_strdup(oldfont->back); |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2788 | g_free(background); |
| 8686 | 2789 | } |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2790 | |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2791 | 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
|
2792 | font->face = family; |
| 8686 | 2793 | gtk_imhtml_toggle_fontface(imhtml, font->face); |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2794 | } else { |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2795 | if (oldfont && oldfont->face) |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2796 | font->face = g_strdup(oldfont->face); |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2797 | g_free(family); |
| 8686 | 2798 | } |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2799 | if (font->face && (atoi(font->face) > 100)) { |
| 8677 | 2800 | /* WTF is this? */ |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
2801 | /* 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
|
2802 | * remember bad things happening if the font size was |
|
9696
9d62e1ec5977
[gaim-migrate @ 10555]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9636
diff
changeset
|
2803 | * 2 billion */ |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2804 | g_free(font->face); |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2805 | font->face = g_strdup("100"); |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2806 | } |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2807 | |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2808 | if (oldfont && oldfont->sml) |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2809 | font->sml = g_strdup(oldfont->sml); |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2810 | |
| 8677 | 2811 | if (size && !(options & GTK_IMHTML_NO_SIZES) && (imhtml->format_functions & (GTK_IMHTML_SHRINK|GTK_IMHTML_GROW))) { |
| 8686 | 2812 | if (g_ascii_strcasecmp(size, "xx-small") == 0) |
| 2813 | font->size = 1; | |
| 2814 | else if (g_ascii_strcasecmp(size, "smaller") == 0 | |
| 2815 | || g_ascii_strcasecmp(size, "x-small") == 0) | |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2816 | font->size = 2; |
| 8686 | 2817 | else if (g_ascii_strcasecmp(size, "larger") == 0 |
| 2818 | || g_ascii_strcasecmp(size, "medium") == 0) | |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2819 | font->size = 4; |
| 8686 | 2820 | else if (g_ascii_strcasecmp(size, "large") == 0) |
| 2821 | font->size = 5; | |
| 2822 | else if (g_ascii_strcasecmp(size, "x-large") == 0) | |
| 2823 | font->size = 6; | |
| 2824 | else if (g_ascii_strcasecmp(size, "xx-large") == 0) | |
| 2825 | font->size = 7; | |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2826 | else |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2827 | font->size = 3; |
| 8686 | 2828 | gtk_imhtml_font_set_size(imhtml, font->size); |
| 2829 | } | |
| 2830 | else if (oldfont) | |
| 2831 | { | |
| 2832 | font->size = oldfont->size; | |
| 2833 | } | |
| 2834 | ||
| 2835 | if (oldfont) | |
| 2836 | { | |
| 2837 | font->underline = oldfont->underline; | |
| 2838 | } | |
| 2839 | if (textdec && font->underline != 1 | |
| 9025 | 2840 | && 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
|
2841 | && (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
|
2842 | && !(options & GTK_IMHTML_NO_FORMATTING)) |
| 8686 | 2843 | { |
| 2844 | gtk_imhtml_toggle_underline(imhtml); | |
| 2845 | font->underline = 1; | |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2846 | } else |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2847 | g_free(textdec); |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2848 | |
| 14395 | 2849 | if (oldfont) |
| 2850 | { | |
| 2851 | font->bold = oldfont->bold; | |
| 2852 | } | |
| 2853 | if (weight) | |
| 2854 | { | |
| 2855 | if(!g_ascii_strcasecmp(weight, "normal")) { | |
| 2856 | font->bold = 0; | |
| 2857 | } else if(!g_ascii_strcasecmp(weight, "bold")) { | |
| 2858 | font->bold = 1; | |
| 2859 | } else if(!g_ascii_strcasecmp(weight, "bolder")) { | |
| 2860 | font->bold++; | |
| 2861 | } else if(!g_ascii_strcasecmp(weight, "lighter")) { | |
| 2862 | if(font->bold > 0) | |
| 2863 | font->bold--; | |
| 2864 | } else { | |
| 2865 | int num = atoi(weight); | |
| 2866 | if(num >= 700) | |
| 2867 | font->bold = 1; | |
| 2868 | else | |
| 2869 | font->bold = 0; | |
| 2870 | } | |
|
17088
1ecea6e2fd97
Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17009
diff
changeset
|
2871 | if (((font->bold && oldfont && !oldfont->bold) || (oldfont && oldfont->bold && !font->bold) || (font->bold && !oldfont)) && !(options & GTK_IMHTML_NO_FORMATTING)) |
| 14395 | 2872 | { |
| 2873 | gtk_imhtml_toggle_bold(imhtml); | |
| 2874 | } | |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2875 | g_free(weight); |
| 14395 | 2876 | } |
| 2877 | ||
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2878 | g_free(style); |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2879 | g_free(size); |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2880 | fonts = g_slist_prepend (fonts, font); |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2881 | } |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2882 | break; |
| 5104 | 2883 | case 57: /* /SPAN */ |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2884 | /* Inline CSS Support - Douglas Thrift */ |
| 8677 | 2885 | if (fonts && !imhtml->wbfo) { |
| 8686 | 2886 | GtkIMHtmlFontDetail *oldfont = NULL; |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2887 | GtkIMHtmlFontDetail *font = fonts->data; |
| 8677 | 2888 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2889 | ws[0] = '\0'; wpos = 0; |
|
8177
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
2890 | /* NEW_BIT (NEW_TEXT_BIT); */ |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2891 | fonts = g_slist_remove (fonts, font); |
| 8692 | 2892 | if (fonts) |
| 2893 | oldfont = fonts->data; | |
| 2894 | ||
| 2895 | if (!oldfont) { | |
| 2896 | 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
|
2897 | if (font->underline && !(options & GTK_IMHTML_NO_FORMATTING)) |
| 8692 | 2898 | 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
|
2899 | if (font->bold && !(options & GTK_IMHTML_NO_FORMATTING)) |
| 14395 | 2900 | 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
|
2901 | 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
|
2902 | 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
|
2903 | 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
|
2904 | 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
|
2905 | 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
|
2906 | gtk_imhtml_toggle_backcolor(imhtml, NULL); |
| 8686 | 2907 | } |
| 8692 | 2908 | else |
| 8686 | 2909 | { |
| 8692 | 2910 | |
|
17088
1ecea6e2fd97
Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17009
diff
changeset
|
2911 | if ((font->size != oldfont->size) && !(options & GTK_IMHTML_NO_SIZES)) |
| 8692 | 2912 | gtk_imhtml_font_set_size(imhtml, oldfont->size); |
| 2913 | ||
|
17088
1ecea6e2fd97
Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17009
diff
changeset
|
2914 | if ((font->underline != oldfont->underline) && !(options & GTK_IMHTML_NO_FORMATTING)) |
| 8692 | 2915 | gtk_imhtml_toggle_underline(imhtml); |
| 2916 | ||
|
17088
1ecea6e2fd97
Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17009
diff
changeset
|
2917 | if (((font->bold && !oldfont->bold) || (oldfont->bold && !font->bold)) && !(options & GTK_IMHTML_NO_FORMATTING)) |
| 14395 | 2918 | gtk_imhtml_toggle_bold(imhtml); |
| 2919 | ||
|
17088
1ecea6e2fd97
Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17009
diff
changeset
|
2920 | if (font->face && (!oldfont->face || strcmp(font->face, oldfont->face) != 0) && !(options & GTK_IMHTML_NO_FONTS)) |
| 8692 | 2921 | gtk_imhtml_toggle_fontface(imhtml, oldfont->face); |
| 2922 | ||
|
17088
1ecea6e2fd97
Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17009
diff
changeset
|
2923 | if (font->fore && (!oldfont->fore || strcmp(font->fore, oldfont->fore) != 0) && !(options & GTK_IMHTML_NO_COLOURS)) |
| 8692 | 2924 | gtk_imhtml_toggle_forecolor(imhtml, oldfont->fore); |
| 2925 | ||
|
17088
1ecea6e2fd97
Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17009
diff
changeset
|
2926 | if (font->back && (!oldfont->back || strcmp(font->back, oldfont->back) != 0) && !(options & GTK_IMHTML_NO_COLOURS)) |
| 8692 | 2927 | gtk_imhtml_toggle_backcolor(imhtml, oldfont->back); |
| 8686 | 2928 | } |
| 8692 | 2929 | |
| 2930 | g_free (font->face); | |
| 2931 | g_free (font->fore); | |
| 2932 | g_free (font->back); | |
| 2933 | g_free (font->sml); | |
| 2934 | ||
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2935 | g_free (font); |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2936 | } |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2937 | break; |
| 8026 | 2938 | case 60: /* SPAN */ |
| 2993 | 2939 | break; |
| 8061 | 2940 | case 62: /* comment */ |
|
8177
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
2941 | /* NEW_BIT (NEW_TEXT_BIT); */ |
| 8317 | 2942 | ws[wpos] = '\0'; |
| 9465 | 2943 | |
| 8677 | 2944 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 2945 | ||
|
10815
b1ca28de65d3
[gaim-migrate @ 12470]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10814
diff
changeset
|
2946 | if (imhtml->show_comments && !(options & GTK_IMHTML_NO_COMMENTS)) { |
|
6124
322206d79652
[gaim-migrate @ 6598]
Mark Doliner <markdoliner@pidgin.im>
parents:
6066
diff
changeset
|
2947 | wpos = g_snprintf (ws, len, "%s", tag); |
|
10815
b1ca28de65d3
[gaim-migrate @ 12470]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10814
diff
changeset
|
2948 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
|
b1ca28de65d3
[gaim-migrate @ 12470]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10814
diff
changeset
|
2949 | } |
|
b1ca28de65d3
[gaim-migrate @ 12470]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10814
diff
changeset
|
2950 | ws[0] = '\0'; wpos = 0; |
|
b1ca28de65d3
[gaim-migrate @ 12470]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10814
diff
changeset
|
2951 | |
|
8177
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
2952 | /* NEW_BIT (NEW_COMMENT_BIT); */ |
| 3922 | 2953 | break; |
| 2954 | default: | |
| 6882 | 2955 | break; |
| 2993 | 2956 | } |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2957 | c += tlen; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2958 | pos += tlen; |
|
13138
4d3bd039da3e
[gaim-migrate @ 15499]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13137
diff
changeset
|
2959 | 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
|
2960 | } else if (imhtml->edit.link == NULL && |
|
a8ef18791524
[gaim-migrate @ 18059]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15111
diff
changeset
|
2961 | gtk_imhtml_is_smiley(imhtml, fonts, c, &smilelen)) { |
| 8473 | 2962 | GtkIMHtmlFontDetail *fd; |
| 2963 | ||
| 2964 | gchar *sml = NULL; | |
| 2965 | if (fonts) { | |
| 2966 | fd = fonts->data; | |
| 2967 | sml = fd->sml; | |
| 2968 | } | |
| 9029 | 2969 | if (!sml) |
| 2970 | sml = imhtml->protocol_name; | |
| 2971 | ||
| 8677 | 2972 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8505 | 2973 | wpos = g_snprintf (ws, smilelen + 1, "%s", c); |
| 8473 | 2974 | |
| 8677 | 2975 | gtk_imhtml_insert_smiley_at_iter(imhtml, sml, ws, iter); |
| 8473 | 2976 | |
| 8505 | 2977 | c += smilelen; |
| 2978 | pos += smilelen; | |
| 8473 | 2979 | wpos = 0; |
| 2980 | ws[0] = 0; | |
| 16144 | 2981 | } else if (*c == '&' && (amp = purple_markup_unescape_entity(c, &tlen))) { |
| 7280 | 2982 | while(*amp) { |
| 2983 | ws [wpos++] = *amp++; | |
| 2984 | } | |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2985 | c += tlen; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2986 | pos += tlen; |
| 1428 | 2987 | } else if (*c == '\n') { |
| 2988 | if (!(options & GTK_IMHTML_NO_NEWLINE)) { | |
| 3922 | 2989 | ws[wpos] = '\n'; |
| 2990 | wpos++; | |
| 8677 | 2991 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 2992 | ws[0] = '\0'; |
| 2993 | wpos = 0; | |
|
8177
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
2994 | /* NEW_BIT (NEW_TEXT_BIT); */ |
| 10217 | 2995 | } else if (!br) { /* Don't insert a space immediately after an HTML break */ |
| 9621 | 2996 | /* A newline is defined by HTML as whitespace, which means we have to replace it with a word boundary. |
| 2997 | * word breaks vary depending on the language used, so the correct thing to do is to use Pango to determine | |
| 2998 | * what language this is, determine the proper word boundary to use, and insert that. I'm just going to insert | |
| 2999 | * a space instead. What are the non-English speakers going to do? Complain in a language I'll understand? | |
| 3000 | * Bu-wahaha! */ | |
| 3001 | ws[wpos] = ' '; | |
| 3002 | wpos++; | |
| 3003 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
| 3004 | ws[0] = '\0'; | |
| 3005 | wpos = 0; | |
| 1428 | 3006 | } |
| 3007 | c++; | |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
3008 | pos++; |
| 8334 | 3009 | } else if ((len_protocol = gtk_imhtml_is_protocol(c)) > 0){ |
| 3010 | while(len_protocol--){ | |
| 8677 | 3011 | /* Skip the next len_protocol characters, but make sure they're |
| 8334 | 3012 | copied into the ws array. |
| 3013 | */ | |
| 3014 | ws [wpos++] = *c++; | |
| 3015 | pos++; | |
| 3016 | } | |
| 8061 | 3017 | } else if (*c) { |
| 1428 | 3018 | ws [wpos++] = *c++; |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
3019 | pos++; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
3020 | } else { |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
3021 | break; |
| 1428 | 3022 | } |
| 3023 | } | |
| 8677 | 3024 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 3025 | ws[0] = '\0'; wpos = 0; |
| 3026 | ||
|
8177
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
3027 | /* NEW_BIT(NEW_TEXT_BIT); */ |
| 8061 | 3028 | |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3029 | if(align_right) { |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3030 | /* 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
|
3031 | GtkTextIter line_iter; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3032 | line_iter = *iter; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3033 | 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
|
3034 | /* insert RLM character to set alignment */ |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3035 | ws[wpos++] = 0xE2; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3036 | ws[wpos++] = 0x80; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3037 | ws[wpos++] = 0x8F; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3038 | |
| 16144 | 3039 | if (!rtl_direction) |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3040 | { |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3041 | /* insert LRM character to set direction */ |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3042 | /* (alignment=right and direction=LTR) */ |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3043 | ws[wpos++] = 0xE2; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3044 | ws[wpos++] = 0x80; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3045 | ws[wpos++] = 0x8E; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3046 | } |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3047 | |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3048 | ws[wpos] = '\0'; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3049 | 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
|
3050 | gtk_text_buffer_get_end_iter(gtk_text_iter_get_buffer(&line_iter), iter); |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3051 | ws[0] = '\0'; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3052 | wpos = 0; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3053 | } |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3054 | |
| 4032 | 3055 | while (fonts) { |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3056 | GtkIMHtmlFontDetail *font = fonts->data; |
| 4032 | 3057 | fonts = g_slist_remove (fonts, font); |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
3058 | g_free (font->face); |
|
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
3059 | g_free (font->fore); |
|
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
3060 | g_free (font->back); |
|
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
3061 | g_free (font->sml); |
| 4032 | 3062 | g_free (font); |
| 3063 | } | |
| 8932 | 3064 | |
| 3065 | g_free(ws); | |
|
13138
4d3bd039da3e
[gaim-migrate @ 15499]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13137
diff
changeset
|
3066 | g_free(bg); |
| 8677 | 3067 | |
| 3068 | if (!imhtml->wbfo) | |
| 8698 | 3069 | gtk_imhtml_close_tags(imhtml, iter); |
| 8506 | 3070 | |
| 15403 | 3071 | object = g_object_ref(G_OBJECT(imhtml)); |
| 8506 | 3072 | g_signal_emit(object, signals[UPDATE_FORMAT], 0); |
| 3073 | g_object_unref(object); | |
| 15420 | 3074 | |
| 3922 | 3075 | } |
| 3076 | ||
| 4892 | 3077 | void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml) |
| 3078 | { | |
| 4288 | 3079 | g_hash_table_destroy(imhtml->smiley_data); |
| 3080 | gtk_smiley_tree_destroy(imhtml->default_smilies); | |
| 4892 | 3081 | imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 4902 | 3082 | g_free, (GDestroyNotify)gtk_smiley_tree_destroy); |
| 4288 | 3083 | imhtml->default_smilies = gtk_smiley_tree_new(); |
| 3084 | } | |
| 8481 | 3085 | |
| 3922 | 3086 | void gtk_imhtml_show_comments (GtkIMHtml *imhtml, |
| 4253 | 3087 | gboolean show) |
| 3088 | { | |
|
6124
322206d79652
[gaim-migrate @ 6598]
Mark Doliner <markdoliner@pidgin.im>
parents:
6066
diff
changeset
|
3089 | imhtml->show_comments = show; |
| 4253 | 3090 | } |
|
1780
431333222954
[gaim-migrate @ 1790]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1738
diff
changeset
|
3091 | |
|
11814
5003711283c0
[gaim-migrate @ 14105]
Richard Laager <rlaager@pidgin.im>
parents:
11768
diff
changeset
|
3092 | const char * |
|
5003711283c0
[gaim-migrate @ 14105]
Richard Laager <rlaager@pidgin.im>
parents:
11768
diff
changeset
|
3093 | gtk_imhtml_get_protocol_name(GtkIMHtml *imhtml) { |
|
5003711283c0
[gaim-migrate @ 14105]
Richard Laager <rlaager@pidgin.im>
parents:
11768
diff
changeset
|
3094 | return imhtml->protocol_name; |
|
5003711283c0
[gaim-migrate @ 14105]
Richard Laager <rlaager@pidgin.im>
parents:
11768
diff
changeset
|
3095 | } |
|
5003711283c0
[gaim-migrate @ 14105]
Richard Laager <rlaager@pidgin.im>
parents:
11768
diff
changeset
|
3096 | |
| 8962 | 3097 | void |
| 9029 | 3098 | 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
|
3099 | g_free(imhtml->protocol_name); |
|
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
3100 | imhtml->protocol_name = g_strdup(protocol_name); |
| 8456 | 3101 | } |
| 3102 | ||
|
1780
431333222954
[gaim-migrate @ 1790]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1738
diff
changeset
|
3103 | void |
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3104 | gtk_imhtml_delete(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) { |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3105 | GList *l; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3106 | GSList *sl; |
|
11234
e23fd86e7581
[gaim-migrate @ 13377]
Daniel Atallah <datallah@pidgin.im>
parents:
11233
diff
changeset
|
3107 | GtkTextIter i, i_s, i_e; |
| 8427 | 3108 | GObject *object = g_object_ref(G_OBJECT(imhtml)); |
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3109 | |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3110 | if (start == NULL) { |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3111 | gtk_text_buffer_get_start_iter(imhtml->text_buffer, &i_s); |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3112 | start = &i_s; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3113 | } |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3114 | |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3115 | if (end == NULL) { |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3116 | gtk_text_buffer_get_end_iter(imhtml->text_buffer, &i_e); |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3117 | end = &i_e; |
| 7991 | 3118 | } |
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3119 | |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3120 | l = imhtml->scalables; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3121 | while (l) { |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3122 | GList *next = l->next; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3123 | struct scalable_data *sd = l->data; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3124 | gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3125 | &i, sd->mark); |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3126 | if (gtk_text_iter_in_range(&i, start, end)) { |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3127 | GtkIMHtmlScalable *scale = sd->scalable; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3128 | scale->free(scale); |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3129 | imhtml->scalables = g_list_remove_link(imhtml->scalables, l); |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3130 | } |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3131 | l = next; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3132 | } |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3133 | |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3134 | sl = imhtml->im_images; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3135 | while (sl) { |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3136 | GSList *next = sl->next; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3137 | struct im_image_data *img_data = sl->data; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3138 | gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3139 | &i, img_data->mark); |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3140 | if (gtk_text_iter_in_range(&i, start, end)) { |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3141 | if (imhtml->funcs->image_unref) |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3142 | imhtml->funcs->image_unref(img_data->id); |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3143 | imhtml->im_images = g_slist_delete_link(imhtml->im_images, sl); |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3144 | g_free(img_data); |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3145 | } |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3146 | sl = next; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3147 | } |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3148 | gtk_text_buffer_delete(imhtml->text_buffer, start, end); |
| 8061 | 3149 | |
| 8427 | 3150 | g_object_unref(object); |
|
1780
431333222954
[gaim-migrate @ 1790]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1738
diff
changeset
|
3151 | } |
|
2363
0767c14d7879
[gaim-migrate @ 2376]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2349
diff
changeset
|
3152 | |
| 4046 | 3153 | void gtk_imhtml_page_up (GtkIMHtml *imhtml) |
| 3154 | { | |
| 5282 | 3155 | GdkRectangle rect; |
| 3156 | GtkTextIter iter; | |
| 4046 | 3157 | |
| 5282 | 3158 | gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); |
| 3159 | gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x, | |
| 3160 | rect.y - rect.height); | |
| 3161 | gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0); | |
| 8061 | 3162 | |
| 4046 | 3163 | } |
| 5282 | 3164 | void gtk_imhtml_page_down (GtkIMHtml *imhtml) |
| 3165 | { | |
| 3166 | GdkRectangle rect; | |
| 3167 | GtkTextIter iter; | |
| 3168 | ||
| 3169 | gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); | |
| 3170 | gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x, | |
| 3171 | rect.y + rect.height); | |
| 3172 | gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0); | |
| 3173 | } | |
| 4735 | 3174 | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3175 | /* GtkIMHtmlScalable, gtk_imhtml_image, gtk_imhtml_hr */ |
| 8962 | 3176 | GtkIMHtmlScalable *gtk_imhtml_image_new(GdkPixbuf *img, const gchar *filename, int id) |
| 4735 | 3177 | { |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3178 | GtkIMHtmlImage *im_image = g_malloc(sizeof(GtkIMHtmlImage)); |
| 4895 | 3179 | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3180 | GTK_IMHTML_SCALABLE(im_image)->scale = gtk_imhtml_image_scale; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3181 | 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
|
3182 | GTK_IMHTML_SCALABLE(im_image)->free = gtk_imhtml_image_free; |
| 5046 | 3183 | |
| 3184 | 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
|
3185 | im_image->image = GTK_IMAGE(gtk_image_new_from_pixbuf(im_image->pixbuf)); |
| 4895 | 3186 | im_image->width = gdk_pixbuf_get_width(img); |
| 3187 | im_image->height = gdk_pixbuf_get_height(img); | |
| 3188 | im_image->mark = NULL; | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
3189 | im_image->filename = g_strdup(filename); |
| 8962 | 3190 | im_image->id = id; |
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3191 | im_image->filesel = NULL; |
| 4895 | 3192 | |
| 5046 | 3193 | g_object_ref(img); |
| 4895 | 3194 | return GTK_IMHTML_SCALABLE(im_image); |
| 3195 | } | |
| 3196 | ||
|
18151
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3197 | static gboolean |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3198 | 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
|
3199 | { |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3200 | GtkIMHtmlImage *im_image; |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3201 | int width, height; |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3202 | int delay; |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3203 | |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3204 | im_image = data; |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3205 | |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3206 | /* Update the pointer to this GdkPixbuf frame of the animation */ |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3207 | g_object_unref(G_OBJECT(im_image->pixbuf)); |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3208 | gdk_pixbuf_animation_iter_advance(GTK_IMHTML_ANIMATION(im_image)->iter, NULL); |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3209 | im_image->pixbuf = gdk_pixbuf_animation_iter_get_pixbuf(GTK_IMHTML_ANIMATION(im_image)->iter); |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3210 | g_object_ref(G_OBJECT(im_image->pixbuf)); |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3211 | |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3212 | /* Update the displayed GtkImage */ |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3213 | width = gdk_pixbuf_get_width(gtk_image_get_pixbuf(im_image->image)); |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3214 | height = gdk_pixbuf_get_height(gtk_image_get_pixbuf(im_image->image)); |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3215 | if (width > 0 && height > 0) |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3216 | { |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3217 | /* Need to scale the new frame to the same size as the old frame */ |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3218 | GdkPixbuf *tmp; |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3219 | tmp = gdk_pixbuf_scale_simple(im_image->pixbuf, width, height, GDK_INTERP_BILINEAR); |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3220 | gtk_image_set_from_pixbuf(im_image->image, tmp); |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3221 | g_object_unref(G_OBJECT(tmp)); |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3222 | } else { |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3223 | /* Display at full-size */ |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3224 | gtk_image_set_from_pixbuf(im_image->image, im_image->pixbuf); |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3225 | } |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3226 | |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3227 | 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
|
3228 | 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
|
3229 | |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3230 | return FALSE; |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3231 | } |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3232 | |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3233 | 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
|
3234 | { |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3235 | GtkIMHtmlImage *im_image = g_malloc(sizeof(GtkIMHtmlAnimation)); |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3236 | |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3237 | 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
|
3238 | 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
|
3239 | 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
|
3240 | |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3241 | 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
|
3242 | 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
|
3243 | GTK_IMHTML_ANIMATION(im_image)->iter = NULL; |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3244 | im_image->pixbuf = gdk_pixbuf_animation_get_static_image(anim); |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3245 | GTK_IMHTML_ANIMATION(im_image)->timer = 0; |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3246 | } else { |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3247 | int delay; |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3248 | GTK_IMHTML_ANIMATION(im_image)->iter = gdk_pixbuf_animation_get_iter(anim, NULL); |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3249 | im_image->pixbuf = gdk_pixbuf_animation_iter_get_pixbuf(GTK_IMHTML_ANIMATION(im_image)->iter); |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3250 | 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
|
3251 | 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
|
3252 | } |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3253 | 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
|
3254 | 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
|
3255 | 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
|
3256 | im_image->mark = NULL; |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3257 | 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
|
3258 | 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
|
3259 | im_image->filesel = NULL; |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3260 | |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3261 | 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
|
3262 | g_object_ref(im_image->pixbuf); |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3263 | |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3264 | 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
|
3265 | } |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3266 | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3267 | void gtk_imhtml_image_scale(GtkIMHtmlScalable *scale, int width, int height) |
| 4895 | 3268 | { |
|
11867
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3269 | GtkIMHtmlImage *im_image = (GtkIMHtmlImage *)scale; |
|
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3270 | |
|
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3271 | if (im_image->width > width || im_image->height > height) { |
|
11840
c9ec5a42d420
[gaim-migrate @ 14131]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11820
diff
changeset
|
3272 | double ratio_w, ratio_h, ratio; |
|
c9ec5a42d420
[gaim-migrate @ 14131]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11820
diff
changeset
|
3273 | int new_h, new_w; |
| 4895 | 3274 | GdkPixbuf *new_image = NULL; |
|
11840
c9ec5a42d420
[gaim-migrate @ 14131]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11820
diff
changeset
|
3275 | |
|
11867
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3276 | ratio_w = ((double)width - 2) / im_image->width; |
|
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3277 | ratio_h = ((double)height - 2) / im_image->height; |
|
11840
c9ec5a42d420
[gaim-migrate @ 14131]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11820
diff
changeset
|
3278 | |
|
c9ec5a42d420
[gaim-migrate @ 14131]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11820
diff
changeset
|
3279 | ratio = (ratio_w < ratio_h) ? ratio_w : ratio_h; |
|
c9ec5a42d420
[gaim-migrate @ 14131]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11820
diff
changeset
|
3280 | |
|
11867
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3281 | new_w = (int)(im_image->width * ratio); |
|
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3282 | new_h = (int)(im_image->height * ratio); |
|
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3283 | |
|
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3284 | 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
|
3285 | gtk_image_set_from_pixbuf(im_image->image, new_image); |
|
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3286 | g_object_unref(G_OBJECT(new_image)); |
|
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3287 | } 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
|
3288 | /* Enough space to show the full-size of the image. */ |
|
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3289 | GdkPixbuf *new_image; |
|
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3290 | |
|
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3291 | 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
|
3292 | gtk_image_set_from_pixbuf(im_image->image, new_image); |
| 4895 | 3293 | g_object_unref(G_OBJECT(new_image)); |
| 3294 | } | |
| 3295 | } | |
| 3296 | ||
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3297 | static void |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3298 | image_save_yes_cb(GtkIMHtmlImage *image, const char *filename) |
| 5012 | 3299 | { |
| 3300 | gchar *type = NULL; | |
| 5019 | 3301 | GError *error = NULL; |
| 5015 | 3302 | #if GTK_CHECK_VERSION(2,2,0) |
| 5012 | 3303 | GSList *formats = gdk_pixbuf_get_formats(); |
|
6162
aed29c41bdfa
[gaim-migrate @ 6642]
Mark Doliner <markdoliner@pidgin.im>
parents:
6124
diff
changeset
|
3304 | #else |
|
aed29c41bdfa
[gaim-migrate @ 6642]
Mark Doliner <markdoliner@pidgin.im>
parents:
6124
diff
changeset
|
3305 | char *basename = g_path_get_basename(filename); |
|
aed29c41bdfa
[gaim-migrate @ 6642]
Mark Doliner <markdoliner@pidgin.im>
parents:
6124
diff
changeset
|
3306 | char *ext = strrchr(basename, '.'); |
|
5959
827dbe4b5bb2
[gaim-migrate @ 6405]
Mark Doliner <markdoliner@pidgin.im>
parents:
5582
diff
changeset
|
3307 | #endif |
|
17694
d7b54168059b
When right-clicking on an image in a GtkIMHtml to save it, if the file
Mark Doliner <markdoliner@pidgin.im>
parents:
17546
diff
changeset
|
3308 | char *newfilename; |
| 5012 | 3309 | |
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3310 | gtk_widget_destroy(image->filesel); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3311 | image->filesel = NULL; |
|
5959
827dbe4b5bb2
[gaim-migrate @ 6405]
Mark Doliner <markdoliner@pidgin.im>
parents:
5582
diff
changeset
|
3312 | |
|
827dbe4b5bb2
[gaim-migrate @ 6405]
Mark Doliner <markdoliner@pidgin.im>
parents:
5582
diff
changeset
|
3313 | #if GTK_CHECK_VERSION(2,2,0) |
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3314 | while (formats) { |
| 5012 | 3315 | GdkPixbufFormat *format = formats->data; |
| 3316 | gchar **extensions = gdk_pixbuf_format_get_extensions(format); | |
| 3317 | gpointer p = extensions; | |
| 3318 | ||
| 3319 | while(gdk_pixbuf_format_is_writable(format) && extensions && extensions[0]){ | |
| 3320 | gchar *fmt_ext = extensions[0]; | |
| 3321 | const gchar* file_ext = filename + strlen(filename) - strlen(fmt_ext); | |
| 3322 | ||
|
17695
5e7fcc2f23cc
Compare the user-entered file extension to the GDK file extension
Mark Doliner <markdoliner@pidgin.im>
parents:
17694
diff
changeset
|
3323 | if(!g_ascii_strcasecmp(fmt_ext, file_ext)){ |
| 5012 | 3324 | type = gdk_pixbuf_format_get_name(format); |
| 3325 | break; | |
| 3326 | } | |
| 3327 | ||
| 3328 | extensions++; | |
| 3329 | } | |
| 3330 | ||
| 3331 | g_strfreev(p); | |
| 3332 | ||
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3333 | if (type) |
| 5012 | 3334 | break; |
| 3335 | ||
| 3336 | formats = formats->next; | |
| 3337 | } | |
| 3338 | ||
| 5020 | 3339 | g_slist_free(formats); |
| 3340 | #else | |
| 3341 | /* this is really ugly code, but I think it will work */ | |
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3342 | if (ext) { |
| 5020 | 3343 | ext++; |
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3344 | if (!g_ascii_strcasecmp(ext, "jpeg") || !g_ascii_strcasecmp(ext, "jpg")) |
| 5020 | 3345 | type = g_strdup("jpeg"); |
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3346 | else if (!g_ascii_strcasecmp(ext, "png")) |
| 5020 | 3347 | type = g_strdup("png"); |
| 3348 | } | |
| 3349 | ||
| 3350 | g_free(basename); | |
| 3351 | #endif | |
| 3352 | ||
| 5012 | 3353 | /* If I can't find a valid type, I will just tell the user about it and then assume |
| 3354 | it's a png */ | |
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3355 | if (!type){ |
|
17694
d7b54168059b
When right-clicking on an image in a GtkIMHtml to save it, if the file
Mark Doliner <markdoliner@pidgin.im>
parents:
17546
diff
changeset
|
3356 | char *basename, *tmp; |
|
11069
3cc1cdd931e9
[gaim-migrate @ 13065]
Richard Laager <rlaager@pidgin.im>
parents:
11019
diff
changeset
|
3357 | #if GTK_CHECK_VERSION(2,4,0) |
|
11019
6786068b00ab
[gaim-migrate @ 12890]
Richard Laager <rlaager@pidgin.im>
parents:
11006
diff
changeset
|
3358 | 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
|
3359 | _("<span size='larger' weight='bold'>Unrecognized file type</span>\n\nDefaulting to PNG.")); |
|
11069
3cc1cdd931e9
[gaim-migrate @ 13065]
Richard Laager <rlaager@pidgin.im>
parents:
11019
diff
changeset
|
3360 | #else |
|
3cc1cdd931e9
[gaim-migrate @ 13065]
Richard Laager <rlaager@pidgin.im>
parents:
11019
diff
changeset
|
3361 | GtkWidget *dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, |
|
3cc1cdd931e9
[gaim-migrate @ 13065]
Richard Laager <rlaager@pidgin.im>
parents:
11019
diff
changeset
|
3362 | _("Unrecognized file type\n\nDefaulting to PNG.")); |
|
3cc1cdd931e9
[gaim-migrate @ 13065]
Richard Laager <rlaager@pidgin.im>
parents:
11019
diff
changeset
|
3363 | #endif |
|
3cc1cdd931e9
[gaim-migrate @ 13065]
Richard Laager <rlaager@pidgin.im>
parents:
11019
diff
changeset
|
3364 | |
|
11019
6786068b00ab
[gaim-migrate @ 12890]
Richard Laager <rlaager@pidgin.im>
parents:
11006
diff
changeset
|
3365 | 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
|
3366 | gtk_widget_show(dialog); |
|
17694
d7b54168059b
When right-clicking on an image in a GtkIMHtml to save it, if the file
Mark Doliner <markdoliner@pidgin.im>
parents:
17546
diff
changeset
|
3367 | |
|
9717
3c8f42ca313e
[gaim-migrate @ 10578]
Mark Doliner <markdoliner@pidgin.im>
parents:
9709
diff
changeset
|
3368 | type = g_strdup("png"); |
|
17694
d7b54168059b
When right-clicking on an image in a GtkIMHtml to save it, if the file
Mark Doliner <markdoliner@pidgin.im>
parents:
17546
diff
changeset
|
3369 | basename = g_path_get_basename(filename); |
|
d7b54168059b
When right-clicking on an image in a GtkIMHtml to save it, if the file
Mark Doliner <markdoliner@pidgin.im>
parents:
17546
diff
changeset
|
3370 | tmp = strrchr(basename, '.'); |
|
d7b54168059b
When right-clicking on an image in a GtkIMHtml to save it, if the file
Mark Doliner <markdoliner@pidgin.im>
parents:
17546
diff
changeset
|
3371 | if (tmp != NULL) |
|
d7b54168059b
When right-clicking on an image in a GtkIMHtml to save it, if the file
Mark Doliner <markdoliner@pidgin.im>
parents:
17546
diff
changeset
|
3372 | tmp[0] = '\0'; |
|
d7b54168059b
When right-clicking on an image in a GtkIMHtml to save it, if the file
Mark Doliner <markdoliner@pidgin.im>
parents:
17546
diff
changeset
|
3373 | newfilename = g_strdup_printf("%s.png", basename); |
|
d7b54168059b
When right-clicking on an image in a GtkIMHtml to save it, if the file
Mark Doliner <markdoliner@pidgin.im>
parents:
17546
diff
changeset
|
3374 | g_free(basename); |
|
d7b54168059b
When right-clicking on an image in a GtkIMHtml to save it, if the file
Mark Doliner <markdoliner@pidgin.im>
parents:
17546
diff
changeset
|
3375 | } else { |
|
d7b54168059b
When right-clicking on an image in a GtkIMHtml to save it, if the file
Mark Doliner <markdoliner@pidgin.im>
parents:
17546
diff
changeset
|
3376 | /* |
|
d7b54168059b
When right-clicking on an image in a GtkIMHtml to save it, if the file
Mark Doliner <markdoliner@pidgin.im>
parents:
17546
diff
changeset
|
3377 | * We're able to save the file in it's original format, so we |
|
d7b54168059b
When right-clicking on an image in a GtkIMHtml to save it, if the file
Mark Doliner <markdoliner@pidgin.im>
parents:
17546
diff
changeset
|
3378 | * can use the original file name. |
|
d7b54168059b
When right-clicking on an image in a GtkIMHtml to save it, if the file
Mark Doliner <markdoliner@pidgin.im>
parents:
17546
diff
changeset
|
3379 | */ |
|
d7b54168059b
When right-clicking on an image in a GtkIMHtml to save it, if the file
Mark Doliner <markdoliner@pidgin.im>
parents:
17546
diff
changeset
|
3380 | newfilename = g_strdup(filename); |
| 5012 | 3381 | } |
| 3382 | ||
|
17694
d7b54168059b
When right-clicking on an image in a GtkIMHtml to save it, if the file
Mark Doliner <markdoliner@pidgin.im>
parents:
17546
diff
changeset
|
3383 | gdk_pixbuf_save(image->pixbuf, newfilename, type, &error, NULL); |
|
d7b54168059b
When right-clicking on an image in a GtkIMHtml to save it, if the file
Mark Doliner <markdoliner@pidgin.im>
parents:
17546
diff
changeset
|
3384 | |
|
d7b54168059b
When right-clicking on an image in a GtkIMHtml to save it, if the file
Mark Doliner <markdoliner@pidgin.im>
parents:
17546
diff
changeset
|
3385 | g_free(newfilename); |
|
d7b54168059b
When right-clicking on an image in a GtkIMHtml to save it, if the file
Mark Doliner <markdoliner@pidgin.im>
parents:
17546
diff
changeset
|
3386 | g_free(type); |
| 5012 | 3387 | |
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3388 | if (error){ |
|
11069
3cc1cdd931e9
[gaim-migrate @ 13065]
Richard Laager <rlaager@pidgin.im>
parents:
11019
diff
changeset
|
3389 | #if GTK_CHECK_VERSION(2,4,0) |
|
11019
6786068b00ab
[gaim-migrate @ 12890]
Richard Laager <rlaager@pidgin.im>
parents:
11006
diff
changeset
|
3390 | 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
|
3391 | _("<span size='larger' weight='bold'>Error saving image</span>\n\n%s"), error->message); |
|
11069
3cc1cdd931e9
[gaim-migrate @ 13065]
Richard Laager <rlaager@pidgin.im>
parents:
11019
diff
changeset
|
3392 | #else |
|
3cc1cdd931e9
[gaim-migrate @ 13065]
Richard Laager <rlaager@pidgin.im>
parents:
11019
diff
changeset
|
3393 | GtkWidget *dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, |
|
3cc1cdd931e9
[gaim-migrate @ 13065]
Richard Laager <rlaager@pidgin.im>
parents:
11019
diff
changeset
|
3394 | _("Error saving image\n\n%s"), error->message); |
|
3cc1cdd931e9
[gaim-migrate @ 13065]
Richard Laager <rlaager@pidgin.im>
parents:
11019
diff
changeset
|
3395 | #endif |
|
11019
6786068b00ab
[gaim-migrate @ 12890]
Richard Laager <rlaager@pidgin.im>
parents:
11006
diff
changeset
|
3396 | 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
|
3397 | gtk_widget_show(dialog); |
| 5012 | 3398 | g_error_free(error); |
| 3399 | } | |
| 3400 | } | |
| 3401 | ||
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3402 | #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3403 | static void |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3404 | image_save_check_if_exists_cb(GtkWidget *widget, gint response, GtkIMHtmlImage *image) |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3405 | { |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3406 | gchar *filename; |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3407 | |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3408 | if (response != GTK_RESPONSE_ACCEPT) { |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3409 | gtk_widget_destroy(widget); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3410 | image->filesel = NULL; |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3411 | return; |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3412 | } |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3413 | |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3414 | filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget)); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3415 | #else /* FILECHOOSER */ |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3416 | static void |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3417 | image_save_check_if_exists_cb(GtkWidget *button, GtkIMHtmlImage *image) |
| 5012 | 3418 | { |
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3419 | gchar *filename; |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3420 | |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3421 | filename = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(image->filesel))); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3422 | |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3423 | if (g_file_test(filename, G_FILE_TEST_IS_DIR)) { |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3424 | gchar *dirname; |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3425 | /* append a / is needed */ |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3426 | if (filename[strlen(filename) - 1] != G_DIR_SEPARATOR) { |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3427 | dirname = g_strconcat(filename, G_DIR_SEPARATOR_S, NULL); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3428 | } else { |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3429 | dirname = g_strdup(filename); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3430 | } |
|
9574
d5a2c770adcd
[gaim-migrate @ 10417]
Mark Doliner <markdoliner@pidgin.im>
parents:
9573
diff
changeset
|
3431 | gtk_file_selection_set_filename(GTK_FILE_SELECTION(image->filesel), dirname); |
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3432 | g_free(dirname); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3433 | g_free(filename); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3434 | return; |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3435 | } |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3436 | #endif /* FILECHOOSER */ |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3437 | |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3438 | /* |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3439 | * 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
|
3440 | * 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
|
3441 | * 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
|
3442 | */ |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3443 | /* |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3444 | if (g_file_test(filename, G_FILE_TEST_EXISTS)) { |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3445 | } else |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3446 | image_save_yes_cb(image, filename); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3447 | */ |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3448 | |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3449 | image_save_yes_cb(image, filename); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3450 | |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3451 | g_free(filename); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3452 | } |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3453 | |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3454 | #if !GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3455 | static void |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3456 | image_save_cancel_cb(GtkIMHtmlImage *image) |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3457 | { |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3458 | gtk_widget_destroy(image->filesel); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3459 | image->filesel = NULL; |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3460 | } |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3461 | #endif /* FILECHOOSER */ |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3462 | |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3463 | static void |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3464 | gtk_imhtml_image_save(GtkWidget *w, GtkIMHtmlImage *image) |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3465 | { |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3466 | if (image->filesel != NULL) { |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3467 | gtk_window_present(GTK_WINDOW(image->filesel)); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3468 | return; |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3469 | } |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3470 | |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3471 | #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3472 | image->filesel = gtk_file_chooser_dialog_new(_("Save Image"), |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3473 | NULL, |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3474 | GTK_FILE_CHOOSER_ACTION_SAVE, |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3475 | GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3476 | GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3477 | NULL); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3478 | 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
|
3479 | if (image->filename != NULL) |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3480 | 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
|
3481 | g_signal_connect(G_OBJECT(GTK_FILE_CHOOSER(image->filesel)), "response", |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3482 | G_CALLBACK(image_save_check_if_exists_cb), image); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3483 | #else /* FILECHOOSER */ |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3484 | image->filesel = gtk_file_selection_new(_("Save Image")); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3485 | if (image->filename != NULL) |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3486 | gtk_file_selection_set_filename(GTK_FILE_SELECTION(image->filesel), image->filename); |
|
9574
d5a2c770adcd
[gaim-migrate @ 10417]
Mark Doliner <markdoliner@pidgin.im>
parents:
9573
diff
changeset
|
3487 | g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(image->filesel)), "delete_event", |
|
d5a2c770adcd
[gaim-migrate @ 10417]
Mark Doliner <markdoliner@pidgin.im>
parents:
9573
diff
changeset
|
3488 | G_CALLBACK(image_save_cancel_cb), image); |
|
d5a2c770adcd
[gaim-migrate @ 10417]
Mark Doliner <markdoliner@pidgin.im>
parents:
9573
diff
changeset
|
3489 | g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(image->filesel)->cancel_button), |
|
d5a2c770adcd
[gaim-migrate @ 10417]
Mark Doliner <markdoliner@pidgin.im>
parents:
9573
diff
changeset
|
3490 | "clicked", G_CALLBACK(image_save_cancel_cb), image); |
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3491 | g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(image->filesel)->ok_button), "clicked", |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3492 | G_CALLBACK(image_save_check_if_exists_cb), image); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3493 | #endif /* FILECHOOSER */ |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3494 | |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3495 | gtk_widget_show(image->filesel); |
| 5012 | 3496 | } |
| 3497 | ||
|
9815
fcbbbce0e1ff
[gaim-migrate @ 10686]
Mark Doliner <markdoliner@pidgin.im>
parents:
9726
diff
changeset
|
3498 | /* |
|
fcbbbce0e1ff
[gaim-migrate @ 10686]
Mark Doliner <markdoliner@pidgin.im>
parents:
9726
diff
changeset
|
3499 | * 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
|
3500 | * 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
|
3501 | * basically like file transfer, except there is an icon to open the file |
| 15884 | 3502 | * 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
|
3503 | * all of that. |
|
fcbbbce0e1ff
[gaim-migrate @ 10686]
Mark Doliner <markdoliner@pidgin.im>
parents:
9726
diff
changeset
|
3504 | */ |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3505 | static gboolean gtk_imhtml_image_clicked(GtkWidget *w, GdkEvent *event, GtkIMHtmlImage *image) |
| 5012 | 3506 | { |
| 3507 | GdkEventButton *event_button = (GdkEventButton *) event; | |
| 3508 | ||
| 3509 | if (event->type == GDK_BUTTON_RELEASE) { | |
| 3510 | if(event_button->button == 3) { | |
| 3511 | GtkWidget *img, *item, *menu; | |
| 3512 | gchar *text = g_strdup_printf(_("_Save Image...")); | |
| 3513 | menu = gtk_menu_new(); | |
| 3514 | ||
| 3515 | /* buttons and such */ | |
| 3516 | img = gtk_image_new_from_stock(GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU); | |
| 3517 | item = gtk_image_menu_item_new_with_mnemonic(text); | |
| 3518 | gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3519 | g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(gtk_imhtml_image_save), image); |
| 5012 | 3520 | gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
| 3521 | ||
| 3522 | gtk_widget_show_all(menu); | |
| 3523 | gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, | |
| 3524 | event_button->button, event_button->time); | |
| 3525 | ||
| 3526 | g_free(text); | |
| 3527 | return TRUE; | |
| 3528 | } | |
| 3529 | } | |
| 3530 | if(event->type == GDK_BUTTON_PRESS && event_button->button == 3) | |
| 3531 | return TRUE; /* Clicking the right mouse button on a link shouldn't | |
| 3532 | be caught by the regular GtkTextView menu */ | |
| 3533 | else | |
| 3534 | return FALSE; /* Let clicks go through if we didn't catch anything */ | |
| 3535 | ||
| 3536 | } | |
|
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
|
3537 | |
|
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
|
3538 | 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
|
3539 | { |
|
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
|
3540 | GdkPixbufAnimation *anim = NULL; |
|
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
|
3541 | GtkIMHtmlScalable *image = NULL; |
|
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
|
3542 | gboolean 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
|
3543 | |
|
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
|
3544 | 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
|
3545 | 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
|
3546 | |
|
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
|
3547 | 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
|
3548 | 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
|
3549 | 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
|
3550 | |
|
18151
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3551 | image = gtk_imhtml_animation_new(anim, smiley->smile, 0); |
|
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
|
3552 | ret = gtk_imhtml_image_clicked(w, event, (GtkIMHtmlImage*)image); |
|
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
|
3553 | g_object_set_data_full(G_OBJECT(w), "image-data", image, (GDestroyNotify)gtk_imhtml_image_free); |
|
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
|
3554 | 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
|
3555 | } |
|
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
|
3556 | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3557 | void gtk_imhtml_image_free(GtkIMHtmlScalable *scale) |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3558 | { |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3559 | GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3560 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3561 | g_object_unref(image->pixbuf); |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
3562 | g_free(image->filename); |
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3563 | if (image->filesel) |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3564 | gtk_widget_destroy(image->filesel); |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3565 | g_free(scale); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3566 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3567 | |
|
18151
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3568 | 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
|
3569 | { |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3570 | 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
|
3571 | |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3572 | 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
|
3573 | 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
|
3574 | 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
|
3575 | 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
|
3576 | 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
|
3577 | |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3578 | 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
|
3579 | } |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3580 | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3581 | 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
|
3582 | { |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3583 | GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3584 | GtkWidget *box = gtk_event_box_new(); |
| 8962 | 3585 | char *tag; |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3586 | GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3587 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3588 | gtk_container_add(GTK_CONTAINER(box), GTK_WIDGET(image->image)); |
| 9229 | 3589 | |
| 3590 | if(!gtk_check_version(2, 4, 0)) | |
| 3591 | g_object_set(G_OBJECT(box), "visible-window", FALSE, NULL); | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3592 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3593 | gtk_widget_show(GTK_WIDGET(image->image)); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3594 | gtk_widget_show(box); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3595 | |
| 8962 | 3596 | tag = g_strdup_printf("<IMG ID=\"%d\">", image->id); |
| 3597 | g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_htmltext", tag, g_free); | |
| 3598 | g_object_set_data(G_OBJECT(anchor), "gtkimhtml_plaintext", "[Image]"); | |
| 3599 | ||
| 15420 | 3600 | gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), box, anchor); |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3601 | g_signal_connect(G_OBJECT(box), "event", G_CALLBACK(gtk_imhtml_image_clicked), image); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3602 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3603 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3604 | GtkIMHtmlScalable *gtk_imhtml_hr_new() |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3605 | { |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3606 | GtkIMHtmlHr *hr = g_malloc(sizeof(GtkIMHtmlHr)); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3607 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3608 | GTK_IMHTML_SCALABLE(hr)->scale = gtk_imhtml_hr_scale; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3609 | GTK_IMHTML_SCALABLE(hr)->add_to = gtk_imhtml_hr_add_to; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3610 | GTK_IMHTML_SCALABLE(hr)->free = gtk_imhtml_hr_free; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3611 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3612 | hr->sep = gtk_hseparator_new(); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3613 | gtk_widget_set_size_request(hr->sep, 5000, 2); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3614 | gtk_widget_show(hr->sep); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3615 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3616 | return GTK_IMHTML_SCALABLE(hr); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3617 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3618 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3619 | void gtk_imhtml_hr_scale(GtkIMHtmlScalable *scale, int width, int height) |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3620 | { |
|
8588
6bcf7ed80ed8
[gaim-migrate @ 9339]
Mark Doliner <markdoliner@pidgin.im>
parents:
8568
diff
changeset
|
3621 | 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
|
3622 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3623 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3624 | 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
|
3625 | { |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3626 | GtkIMHtmlHr *hr = (GtkIMHtmlHr *)scale; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3627 | GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); |
| 8698 | 3628 | g_object_set_data(G_OBJECT(anchor), "gtkimhtml_htmltext", "<hr>"); |
| 3629 | g_object_set_data(G_OBJECT(anchor), "gtkimhtml_plaintext", "\n---\n"); | |
| 15420 | 3630 | 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
|
3631 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3632 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3633 | void gtk_imhtml_hr_free(GtkIMHtmlScalable *scale) |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3634 | { |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3635 | g_free(scale); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3636 | } |
| 7295 | 3637 | |
| 3638 | gboolean gtk_imhtml_search_find(GtkIMHtml *imhtml, const gchar *text) | |
| 3639 | { | |
| 3640 | GtkTextIter iter, start, end; | |
| 3641 | gboolean new_search = TRUE; | |
|
14863
82888d51234c
[gaim-migrate @ 17566]
Daniel Atallah <datallah@pidgin.im>
parents:
14821
diff
changeset
|
3642 | GtkTextMark *start_mark; |
| 7295 | 3643 | |
| 3644 | g_return_val_if_fail(imhtml != NULL, FALSE); | |
| 3645 | g_return_val_if_fail(text != NULL, FALSE); | |
| 8061 | 3646 | |
|
14863
82888d51234c
[gaim-migrate @ 17566]
Daniel Atallah <datallah@pidgin.im>
parents:
14821
diff
changeset
|
3647 | start_mark = gtk_text_buffer_get_mark(imhtml->text_buffer, "search"); |
|
82888d51234c
[gaim-migrate @ 17566]
Daniel Atallah <datallah@pidgin.im>
parents:
14821
diff
changeset
|
3648 | |
|
82888d51234c
[gaim-migrate @ 17566]
Daniel Atallah <datallah@pidgin.im>
parents:
14821
diff
changeset
|
3649 | if (start_mark && imhtml->search_string && !strcmp(text, imhtml->search_string)) |
| 7295 | 3650 | new_search = FALSE; |
| 8061 | 3651 | |
| 7295 | 3652 | if (new_search) { |
| 3653 | gtk_imhtml_search_clear(imhtml); | |
|
14863
82888d51234c
[gaim-migrate @ 17566]
Daniel Atallah <datallah@pidgin.im>
parents:
14821
diff
changeset
|
3654 | g_free(imhtml->search_string); |
|
82888d51234c
[gaim-migrate @ 17566]
Daniel Atallah <datallah@pidgin.im>
parents:
14821
diff
changeset
|
3655 | imhtml->search_string = g_strdup(text); |
| 15093 | 3656 | gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); |
| 7295 | 3657 | } else { |
| 3658 | 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
|
3659 | start_mark); |
| 7295 | 3660 | } |
| 3661 | ||
| 15093 | 3662 | if (gtk_source_iter_backward_search(&iter, imhtml->search_string, |
|
14400
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3663 | GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_CASE_INSENSITIVE, |
|
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3664 | &start, &end, NULL)) |
|
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3665 | { |
| 7295 | 3666 | gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &start, 0, TRUE, 0, 0); |
| 15093 | 3667 | 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
|
3668 | if (new_search) |
|
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3669 | { |
| 7295 | 3670 | gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &iter, &end); |
| 8061 | 3671 | do |
| 7295 | 3672 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "search", &start, &end); |
| 15093 | 3673 | while (gtk_source_iter_backward_search(&start, imhtml->search_string, |
| 8061 | 3674 | GTK_SOURCE_SEARCH_VISIBLE_ONLY | |
| 7358 | 3675 | GTK_SOURCE_SEARCH_CASE_INSENSITIVE, |
| 7295 | 3676 | &start, &end, NULL)); |
| 3677 | } | |
| 3678 | return TRUE; | |
| 3679 | } | |
|
14400
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3680 | else if (!new_search) |
|
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3681 | { |
|
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3682 | /* We hit the end, so start at the beginning again. */ |
| 15093 | 3683 | gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); |
| 3684 | ||
| 3685 | if (gtk_source_iter_backward_search(&iter, imhtml->search_string, | |
|
14400
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3686 | GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_CASE_INSENSITIVE, |
|
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3687 | &start, &end, NULL)) |
|
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3688 | { |
|
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3689 | gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &start, 0, TRUE, 0, 0); |
| 15093 | 3690 | 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
|
3691 | |
|
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3692 | return TRUE; |
|
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3693 | } |
|
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3694 | |
|
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3695 | } |
| 8061 | 3696 | |
| 7295 | 3697 | return FALSE; |
| 3698 | } | |
| 3699 | ||
| 3700 | void gtk_imhtml_search_clear(GtkIMHtml *imhtml) | |
| 3701 | { | |
| 3702 | GtkTextIter start, end; | |
| 8061 | 3703 | |
| 7295 | 3704 | g_return_if_fail(imhtml != NULL); |
| 8061 | 3705 | |
| 7295 | 3706 | gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); |
| 3707 | gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
| 3708 | ||
| 3709 | 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
|
3710 | g_free(imhtml->search_string); |
| 7295 | 3711 | imhtml->search_string = NULL; |
| 3712 | } | |
| 8061 | 3713 | |
| 8677 | 3714 | static GtkTextTag *find_font_forecolor_tag(GtkIMHtml *imhtml, gchar *color) |
| 3715 | { | |
| 3716 | gchar str[18]; | |
| 3717 | GtkTextTag *tag; | |
| 3718 | ||
| 3719 | g_snprintf(str, sizeof(str), "FORECOLOR %s", color); | |
| 3720 | ||
| 3721 | tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
| 10858 | 3722 | if (!tag) { |
| 3723 | GdkColor gcolor; | |
| 3724 | if (!gdk_color_parse(color, &gcolor)) { | |
| 3725 | gchar tmp[8]; | |
| 3726 | tmp[0] = '#'; | |
| 3727 | strncpy(&tmp[1], color, 7); | |
| 3728 | tmp[7] = '\0'; | |
| 3729 | if (!gdk_color_parse(tmp, &gcolor)) | |
| 3730 | gdk_color_parse("black", &gcolor); | |
| 3731 | } | |
| 3732 | tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground-gdk", &gcolor, NULL); | |
| 3733 | } | |
| 8677 | 3734 | |
| 3735 | return tag; | |
| 3736 | } | |
| 3737 | ||
| 3738 | static GtkTextTag *find_font_backcolor_tag(GtkIMHtml *imhtml, gchar *color) | |
| 3739 | { | |
| 3740 | gchar str[18]; | |
| 3741 | GtkTextTag *tag; | |
| 3742 | ||
| 3743 | g_snprintf(str, sizeof(str), "BACKCOLOR %s", color); | |
| 3744 | ||
| 3745 | tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
| 10858 | 3746 | if (!tag) { |
| 3747 | GdkColor gcolor; | |
| 3748 | if (!gdk_color_parse(color, &gcolor)) { | |
| 3749 | gchar tmp[8]; | |
| 3750 | tmp[0] = '#'; | |
| 3751 | strncpy(&tmp[1], color, 7); | |
| 3752 | tmp[7] = '\0'; | |
| 3753 | if (!gdk_color_parse(tmp, &gcolor)) | |
| 3754 | gdk_color_parse("white", &gcolor); | |
| 3755 | } | |
| 3756 | tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "background-gdk", &gcolor, NULL); | |
| 3757 | } | |
| 8677 | 3758 | |
| 3759 | return tag; | |
| 3760 | } | |
| 3761 | ||
| 10776 | 3762 | static GtkTextTag *find_font_background_tag(GtkIMHtml *imhtml, gchar *color) |
| 3763 | { | |
| 3764 | gchar str[19]; | |
| 3765 | GtkTextTag *tag; | |
| 3766 | ||
| 3767 | g_snprintf(str, sizeof(str), "BACKGROUND %s", color); | |
| 3768 | ||
| 3769 | tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
| 3770 | if (!tag) | |
| 3771 | tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, NULL); | |
| 3772 | ||
| 3773 | return tag; | |
| 3774 | } | |
| 3775 | ||
| 8677 | 3776 | static GtkTextTag *find_font_face_tag(GtkIMHtml *imhtml, gchar *face) |
| 8061 | 3777 | { |
| 8677 | 3778 | gchar str[256]; |
| 3779 | GtkTextTag *tag; | |
| 3780 | ||
| 3781 | g_snprintf(str, sizeof(str), "FONT FACE %s", face); | |
| 3782 | str[255] = '\0'; | |
| 3783 | ||
| 3784 | tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
| 3785 | if (!tag) | |
| 3786 | tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "family", face, NULL); | |
| 3787 | ||
| 3788 | return tag; | |
| 3789 | } | |
| 3790 | ||
| 3791 | static GtkTextTag *find_font_size_tag(GtkIMHtml *imhtml, int size) | |
| 3792 | { | |
| 3793 | gchar str[24]; | |
| 3794 | GtkTextTag *tag; | |
| 3795 | ||
| 3796 | g_snprintf(str, sizeof(str), "FONT SIZE %d", size); | |
| 3797 | str[23] = '\0'; | |
| 3798 | ||
| 3799 | tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
| 3800 | if (!tag) { | |
| 10525 | 3801 | /* For reasons I don't understand, setting "scale" here scaled |
| 3802 | * based on some default size other than my theme's default | |
| 3803 | * size. Our size 4 was actually smaller than our size 3 for | |
| 3804 | * me. So this works around that oddity. | |
| 8677 | 3805 | */ |
| 10525 | 3806 | GtkTextAttributes *attr = gtk_text_view_get_default_attributes(GTK_TEXT_VIEW(imhtml)); |
| 8677 | 3807 | tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "size", |
| 10525 | 3808 | (gint) (pango_font_description_get_size(attr->font) * |
|
10899
87d9aec5b72d
[gaim-migrate @ 12619]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10871
diff
changeset
|
3809 | (double) POINT_SIZE(size)), NULL); |
| 10525 | 3810 | gtk_text_attributes_unref(attr); |
| 8061 | 3811 | } |
| 3812 | ||
| 8677 | 3813 | return tag; |
| 3814 | } | |
| 3815 | ||
| 3816 | static void remove_tag_by_prefix(GtkIMHtml *imhtml, const GtkTextIter *i, const GtkTextIter *e, | |
| 3817 | const char *prefix, guint len, gboolean homo) | |
| 3818 | { | |
| 3819 | GSList *tags, *l; | |
| 3820 | GtkTextIter iter; | |
| 3821 | ||
| 3822 | tags = gtk_text_iter_get_tags(i); | |
| 3823 | ||
| 3824 | for (l = tags; l; l = l->next) { | |
| 3825 | GtkTextTag *tag = l->data; | |
| 3826 | ||
| 3827 | if (tag->name && !strncmp(tag->name, prefix, len)) | |
| 3828 | gtk_text_buffer_remove_tag(imhtml->text_buffer, tag, i, e); | |
| 8061 | 3829 | } |
| 3830 | ||
| 8677 | 3831 | g_slist_free(tags); |
| 3832 | ||
| 3833 | if (homo) | |
| 3834 | return; | |
| 3835 | ||
| 3836 | iter = *i; | |
| 3837 | ||
| 3838 | while (gtk_text_iter_forward_char(&iter) && !gtk_text_iter_equal(&iter, e)) { | |
| 3839 | if (gtk_text_iter_begins_tag(&iter, NULL)) { | |
| 3840 | tags = gtk_text_iter_get_toggled_tags(&iter, TRUE); | |
| 3841 | ||
| 3842 | for (l = tags; l; l = l->next) { | |
| 3843 | GtkTextTag *tag = l->data; | |
| 3844 | ||
| 3845 | if (tag->name && !strncmp(tag->name, prefix, len)) | |
| 3846 | gtk_text_buffer_remove_tag(imhtml->text_buffer, tag, &iter, e); | |
| 3847 | } | |
| 3848 | ||
| 3849 | g_slist_free(tags); | |
| 3850 | } | |
| 8061 | 3851 | } |
| 8677 | 3852 | } |
| 3853 | ||
| 3854 | static void remove_font_size(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
| 3855 | { | |
| 3856 | remove_tag_by_prefix(imhtml, i, e, "FONT SIZE ", 10, homo); | |
| 3857 | } | |
| 3858 | ||
| 3859 | static void remove_font_face(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
| 3860 | { | |
| 3861 | remove_tag_by_prefix(imhtml, i, e, "FONT FACE ", 10, homo); | |
| 3862 | } | |
| 3863 | ||
| 3864 | static void remove_font_forecolor(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
| 3865 | { | |
| 3866 | remove_tag_by_prefix(imhtml, i, e, "FORECOLOR ", 10, homo); | |
| 3867 | } | |
| 3868 | ||
| 3869 | static void remove_font_backcolor(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
| 3870 | { | |
| 3871 | remove_tag_by_prefix(imhtml, i, e, "BACKCOLOR ", 10, homo); | |
| 3872 | } | |
| 3873 | ||
| 10776 | 3874 | static void remove_font_background(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) |
| 3875 | { | |
| 3876 | remove_tag_by_prefix(imhtml, i, e, "BACKGROUND ", 10, homo); | |
| 3877 | } | |
| 3878 | ||
| 8677 | 3879 | static void remove_font_link(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) |
| 3880 | { | |
| 3881 | remove_tag_by_prefix(imhtml, i, e, "LINK ", 5, homo); | |
| 3882 | } | |
| 3883 | ||
|
12672
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3884 | static void |
|
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3885 | imhtml_clear_formatting(GtkIMHtml *imhtml) |
|
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3886 | { |
|
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3887 | GtkTextIter start, end; |
|
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3888 | |
|
12796
8fb3611a91e1
[gaim-migrate @ 15143]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12673
diff
changeset
|
3889 | if (!imhtml->editable) |
|
8fb3611a91e1
[gaim-migrate @ 15143]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12673
diff
changeset
|
3890 | return; |
|
8fb3611a91e1
[gaim-migrate @ 15143]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12673
diff
changeset
|
3891 | |
|
8fb3611a91e1
[gaim-migrate @ 15143]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12673
diff
changeset
|
3892 | if (imhtml->wbfo) |
|
8fb3611a91e1
[gaim-migrate @ 15143]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12673
diff
changeset
|
3893 | gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
|
8fb3611a91e1
[gaim-migrate @ 15143]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12673
diff
changeset
|
3894 | else |
|
8fb3611a91e1
[gaim-migrate @ 15143]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12673
diff
changeset
|
3895 | if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) |
|
8fb3611a91e1
[gaim-migrate @ 15143]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12673
diff
changeset
|
3896 | gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
|
12672
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3897 | |
|
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3898 | 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
|
3899 | 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
|
3900 | 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
|
3901 | 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
|
3902 | remove_font_size(imhtml, &start, &end, FALSE); |
|
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3903 | remove_font_face(imhtml, &start, &end, FALSE); |
|
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3904 | remove_font_forecolor(imhtml, &start, &end, FALSE); |
|
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3905 | remove_font_backcolor(imhtml, &start, &end, FALSE); |
|
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3906 | remove_font_background(imhtml, &start, &end, FALSE); |
|
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3907 | remove_font_link(imhtml, &start, &end, FALSE); |
|
12672
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3908 | |
|
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3909 | imhtml->edit.bold = 0; |
|
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3910 | imhtml->edit.italic = 0; |
|
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3911 | imhtml->edit.underline = 0; |
|
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3912 | imhtml->edit.strike = 0; |
|
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3913 | imhtml->edit.fontsize = 0; |
|
13224
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3914 | |
|
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3915 | g_free(imhtml->edit.fontface); |
|
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3916 | imhtml->edit.fontface = NULL; |
|
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3917 | |
|
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3918 | g_free(imhtml->edit.forecolor); |
|
12672
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3919 | imhtml->edit.forecolor = NULL; |
|
13224
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3920 | |
|
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3921 | g_free(imhtml->edit.backcolor); |
|
12672
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3922 | imhtml->edit.backcolor = NULL; |
|
13224
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3923 | |
|
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3924 | g_free(imhtml->edit.background); |
|
12672
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3925 | imhtml->edit.background = NULL; |
|
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3926 | } |
|
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3927 | |
| 8677 | 3928 | /* Editable stuff */ |
| 3929 | static void preinsert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml) | |
| 3930 | { | |
| 3931 | imhtml->insert_offset = gtk_text_iter_get_offset(iter); | |
| 3932 | } | |
| 3933 | ||
| 10169 | 3934 | static void insert_ca_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextChildAnchor *arg2, gpointer user_data) |
| 3935 | { | |
| 3936 | GtkTextIter start; | |
| 3937 | ||
| 3938 | start = *arg1; | |
| 3939 | gtk_text_iter_backward_char(&start); | |
| 3940 | ||
| 3941 | gtk_imhtml_apply_tags_on_insert(user_data, &start, arg1); | |
| 3942 | } | |
| 3943 | ||
| 8677 | 3944 | static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *end, gchar *text, gint len, GtkIMHtml *imhtml) |
| 3945 | { | |
| 3946 | GtkTextIter start; | |
| 3947 | ||
| 3948 | if (!len) | |
| 3949 | return; | |
| 3950 | ||
| 3951 | start = *end; | |
| 3952 | gtk_text_iter_set_offset(&start, imhtml->insert_offset); | |
| 3953 | ||
| 10169 | 3954 | gtk_imhtml_apply_tags_on_insert(imhtml, &start, end); |
| 3955 | } | |
| 3956 | ||
|
12673
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3957 | 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
|
3958 | { |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3959 | GSList *tags, *l; |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3960 | |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3961 | tags = gtk_text_iter_get_tags(start); |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3962 | for (l = tags; l != NULL; l = l->next) { |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3963 | GtkTextTag *tag = GTK_TEXT_TAG(l->data); |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3964 | |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3965 | if (tag && /* Remove the formatting only if */ |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3966 | gtk_text_iter_starts_word(start) && /* beginning of a word */ |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3967 | 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
|
3968 | (!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
|
3969 | gtk_text_iter_ends_tag(end, tag))) { |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3970 | gtk_text_buffer_remove_tag(imhtml->text_buffer, tag, start, end); |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3971 | if (tag->name && |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3972 | strncmp(tag->name, "LINK ", 5) == 0 && imhtml->edit.link) { |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3973 | gtk_imhtml_toggle_link(imhtml, NULL); |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3974 | } |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
3975 | } |
|
12673
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3976 | } |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3977 | g_slist_free(tags); |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3978 | } |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3979 | |
| 10169 | 3980 | static void gtk_imhtml_apply_tags_on_insert(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) |
| 3981 | { | |
| 8677 | 3982 | if (imhtml->edit.bold) |
| 10169 | 3983 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", start, end); |
| 8677 | 3984 | else |
| 10169 | 3985 | gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", start, end); |
| 8677 | 3986 | |
| 3987 | if (imhtml->edit.italic) | |
| 10169 | 3988 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", start, end); |
| 8677 | 3989 | else |
| 10169 | 3990 | gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", start, end); |
| 8677 | 3991 | |
| 3992 | if (imhtml->edit.underline) | |
| 10169 | 3993 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", start, end); |
| 8677 | 3994 | else |
| 10169 | 3995 | gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", start, end); |
| 8677 | 3996 | |
| 9924 | 3997 | if (imhtml->edit.strike) |
| 10169 | 3998 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", start, end); |
| 9924 | 3999 | else |
| 10169 | 4000 | gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", start, end); |
| 9924 | 4001 | |
| 8677 | 4002 | if (imhtml->edit.forecolor) { |
| 10169 | 4003 | remove_font_forecolor(imhtml, start, end, TRUE); |
| 8677 | 4004 | gtk_text_buffer_apply_tag(imhtml->text_buffer, |
| 4005 | find_font_forecolor_tag(imhtml, imhtml->edit.forecolor), | |
| 10169 | 4006 | start, end); |
| 8061 | 4007 | } |
| 4008 | ||
| 8677 | 4009 | if (imhtml->edit.backcolor) { |
| 10169 | 4010 | remove_font_backcolor(imhtml, start, end, TRUE); |
| 8677 | 4011 | gtk_text_buffer_apply_tag(imhtml->text_buffer, |
| 4012 | find_font_backcolor_tag(imhtml, imhtml->edit.backcolor), | |
| 10169 | 4013 | start, end); |
| 8677 | 4014 | } |
| 4015 | ||
| 10776 | 4016 | if (imhtml->edit.background) { |
| 4017 | remove_font_background(imhtml, start, end, TRUE); | |
| 4018 | gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 4019 | find_font_background_tag(imhtml, imhtml->edit.background), | |
| 4020 | start, end); | |
| 4021 | } | |
| 8677 | 4022 | if (imhtml->edit.fontface) { |
| 10169 | 4023 | remove_font_face(imhtml, start, end, TRUE); |
| 8677 | 4024 | gtk_text_buffer_apply_tag(imhtml->text_buffer, |
| 4025 | find_font_face_tag(imhtml, imhtml->edit.fontface), | |
| 10169 | 4026 | start, end); |
| 8061 | 4027 | } |
| 8677 | 4028 | |
| 4029 | if (imhtml->edit.fontsize) { | |
| 10169 | 4030 | remove_font_size(imhtml, start, end, TRUE); |
| 8677 | 4031 | gtk_text_buffer_apply_tag(imhtml->text_buffer, |
| 4032 | find_font_size_tag(imhtml, imhtml->edit.fontsize), | |
| 10169 | 4033 | start, end); |
| 8677 | 4034 | } |
| 4035 | ||
| 4036 | if (imhtml->edit.link) { | |
| 10169 | 4037 | remove_font_link(imhtml, start, end, TRUE); |
| 8677 | 4038 | gtk_text_buffer_apply_tag(imhtml->text_buffer, |
| 4039 | imhtml->edit.link, | |
| 10169 | 4040 | start, end); |
| 8677 | 4041 | } |
| 8061 | 4042 | } |
| 4043 | ||
| 4044 | void gtk_imhtml_set_editable(GtkIMHtml *imhtml, gboolean editable) | |
| 4045 | { | |
| 4046 | gtk_text_view_set_editable(GTK_TEXT_VIEW(imhtml), editable); | |
|
8177
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
4047 | /* |
|
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
4048 | * We need a visible caret for accessibility, so mouseless |
|
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
4049 | * people can highlight stuff. |
|
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
4050 | */ |
|
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
4051 | /* gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(imhtml), editable); */ |
| 8061 | 4052 | imhtml->editable = editable; |
| 8677 | 4053 | imhtml->format_functions = GTK_IMHTML_ALL; |
| 4054 | ||
| 4055 | if (editable) | |
| 4056 | g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set", | |
| 4057 | G_CALLBACK(mark_set_cb), imhtml); | |
| 4058 | } | |
| 4059 | ||
| 4060 | void gtk_imhtml_set_whole_buffer_formatting_only(GtkIMHtml *imhtml, gboolean wbfo) | |
| 4061 | { | |
| 4062 | g_return_if_fail(imhtml != NULL); | |
| 4063 | ||
| 4064 | imhtml->wbfo = wbfo; | |
| 8420 | 4065 | } |
| 4066 | ||
| 4067 | void gtk_imhtml_set_format_functions(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons) | |
| 4068 | { | |
| 4069 | GObject *object = g_object_ref(G_OBJECT(imhtml)); | |
| 8677 | 4070 | imhtml->format_functions = buttons; |
| 8420 | 4071 | g_signal_emit(object, signals[BUTTONS_UPDATE], 0, buttons); |
| 4072 | g_object_unref(object); | |
| 8061 | 4073 | } |
| 4074 | ||
|
8788
a13634443a38
[gaim-migrate @ 9550]
Mark Doliner <markdoliner@pidgin.im>
parents:
8786
diff
changeset
|
4075 | GtkIMHtmlButtons gtk_imhtml_get_format_functions(GtkIMHtml *imhtml) |
|
a13634443a38
[gaim-migrate @ 9550]
Mark Doliner <markdoliner@pidgin.im>
parents:
8786
diff
changeset
|
4076 | { |
|
a13634443a38
[gaim-migrate @ 9550]
Mark Doliner <markdoliner@pidgin.im>
parents:
8786
diff
changeset
|
4077 | return imhtml->format_functions; |
|
a13634443a38
[gaim-migrate @ 9550]
Mark Doliner <markdoliner@pidgin.im>
parents:
8786
diff
changeset
|
4078 | } |
| 8516 | 4079 | |
| 4080 | void gtk_imhtml_get_current_format(GtkIMHtml *imhtml, gboolean *bold, | |
| 4081 | gboolean *italic, gboolean *underline) | |
| 8481 | 4082 | { |
|
12900
7fe519669e07
[gaim-migrate @ 15253]
Richard Laager <rlaager@pidgin.im>
parents:
12836
diff
changeset
|
4083 | if (bold != NULL) |
|
7fe519669e07
[gaim-migrate @ 15253]
Richard Laager <rlaager@pidgin.im>
parents:
12836
diff
changeset
|
4084 | (*bold) = imhtml->edit.bold; |
|
7fe519669e07
[gaim-migrate @ 15253]
Richard Laager <rlaager@pidgin.im>
parents:
12836
diff
changeset
|
4085 | if (italic != NULL) |
|
7fe519669e07
[gaim-migrate @ 15253]
Richard Laager <rlaager@pidgin.im>
parents:
12836
diff
changeset
|
4086 | (*italic) = imhtml->edit.italic; |
|
7fe519669e07
[gaim-migrate @ 15253]
Richard Laager <rlaager@pidgin.im>
parents:
12836
diff
changeset
|
4087 | if (underline != NULL) |
|
7fe519669e07
[gaim-migrate @ 15253]
Richard Laager <rlaager@pidgin.im>
parents:
12836
diff
changeset
|
4088 | (*underline) = imhtml->edit.underline; |
| 8481 | 4089 | } |
| 4090 | ||
| 9025 | 4091 | char * |
| 4092 | gtk_imhtml_get_current_fontface(GtkIMHtml *imhtml) | |
| 4093 | { | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
4094 | return g_strdup(imhtml->edit.fontface); |
| 9025 | 4095 | } |
| 4096 | ||
| 4097 | char * | |
| 4098 | gtk_imhtml_get_current_forecolor(GtkIMHtml *imhtml) | |
| 4099 | { | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
4100 | return g_strdup(imhtml->edit.forecolor); |
| 9025 | 4101 | } |
| 4102 | ||
| 4103 | char * | |
| 4104 | gtk_imhtml_get_current_backcolor(GtkIMHtml *imhtml) | |
| 4105 | { | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
4106 | return g_strdup(imhtml->edit.backcolor); |
| 9025 | 4107 | } |
| 4108 | ||
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4109 | char * |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4110 | gtk_imhtml_get_current_background(GtkIMHtml *imhtml) |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4111 | { |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
4112 | return g_strdup(imhtml->edit.background); |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4113 | } |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4114 | |
| 9025 | 4115 | gint |
| 4116 | gtk_imhtml_get_current_fontsize(GtkIMHtml *imhtml) | |
| 4117 | { | |
| 4118 | return imhtml->edit.fontsize; | |
| 4119 | } | |
| 4120 | ||
| 8061 | 4121 | gboolean gtk_imhtml_get_editable(GtkIMHtml *imhtml) |
| 4122 | { | |
| 4123 | return imhtml->editable; | |
| 4124 | } | |
| 4125 | ||
|
11269
ca63789d57b9
[gaim-migrate @ 13451]
Richard Laager <rlaager@pidgin.im>
parents:
11267
diff
changeset
|
4126 | void |
|
ca63789d57b9
[gaim-migrate @ 13451]
Richard Laager <rlaager@pidgin.im>
parents:
11267
diff
changeset
|
4127 | gtk_imhtml_clear_formatting(GtkIMHtml *imhtml) |
|
ca63789d57b9
[gaim-migrate @ 13451]
Richard Laager <rlaager@pidgin.im>
parents:
11267
diff
changeset
|
4128 | { |
|
11275
cdcc651d7ecd
[gaim-migrate @ 13461]
Richard Laager <rlaager@pidgin.im>
parents:
11269
diff
changeset
|
4129 | GObject *object; |
|
cdcc651d7ecd
[gaim-migrate @ 13461]
Richard Laager <rlaager@pidgin.im>
parents:
11269
diff
changeset
|
4130 | |
|
cdcc651d7ecd
[gaim-migrate @ 13461]
Richard Laager <rlaager@pidgin.im>
parents:
11269
diff
changeset
|
4131 | object = g_object_ref(G_OBJECT(imhtml)); |
|
cdcc651d7ecd
[gaim-migrate @ 13461]
Richard Laager <rlaager@pidgin.im>
parents:
11269
diff
changeset
|
4132 | g_signal_emit(object, signals[CLEAR_FORMAT], 0); |
|
11276
aec923529d31
[gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents:
11275
diff
changeset
|
4133 | |
|
11269
ca63789d57b9
[gaim-migrate @ 13451]
Richard Laager <rlaager@pidgin.im>
parents:
11267
diff
changeset
|
4134 | gtk_widget_grab_focus(GTK_WIDGET(imhtml)); |
|
11276
aec923529d31
[gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents:
11275
diff
changeset
|
4135 | |
|
aec923529d31
[gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents:
11275
diff
changeset
|
4136 | g_object_unref(object); |
|
11269
ca63789d57b9
[gaim-migrate @ 13451]
Richard Laager <rlaager@pidgin.im>
parents:
11267
diff
changeset
|
4137 | } |
|
ca63789d57b9
[gaim-migrate @ 13451]
Richard Laager <rlaager@pidgin.im>
parents:
11267
diff
changeset
|
4138 | |
| 8677 | 4139 | /* |
| 4140 | * I had this crazy idea about changing the text cursor color to reflex the foreground color | |
| 4141 | * of the text about to be entered. This is the place you'd do it, along with the place where | |
| 4142 | * we actually set a new foreground color. | |
| 15884 | 4143 | * I may not do this, because people will bitch about Purple overriding their gtk theme's cursor |
| 8677 | 4144 | * colors. |
| 4145 | * | |
| 4146 | * Just in case I do do this, I asked about what to set the secondary text cursor to. | |
| 4147 | * | |
| 8719 | 4148 | * (12:45:27) ?? ???: secondary_cursor_color = (rgb(background) + rgb(primary_cursor_color) ) / 2 |
| 4149 | * (12:45:55) ?? ???: understand? | |
| 8677 | 4150 | * (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
|
4151 | * (12:46:56) ?? ???: u might need to extract separate each color from RGB |
| 8677 | 4152 | */ |
| 4153 | ||
| 4154 | static void mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, | |
| 4155 | GtkIMHtml *imhtml) | |
| 4156 | { | |
| 4157 | GSList *tags, *l; | |
| 4158 | GtkTextIter iter; | |
| 4159 | ||
| 4160 | if (mark != gtk_text_buffer_get_insert(buffer)) | |
| 4161 | return; | |
| 4162 | ||
| 4163 | if (!gtk_text_buffer_get_char_count(buffer)) | |
| 4164 | return; | |
| 4165 | ||
| 9924 | 4166 | 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
|
4167 | g_free(imhtml->edit.forecolor); |
| 8677 | 4168 | imhtml->edit.forecolor = NULL; |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
4169 | |
|
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
4170 | g_free(imhtml->edit.backcolor); |
| 8677 | 4171 | imhtml->edit.backcolor = NULL; |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
4172 | |
|
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
4173 | g_free(imhtml->edit.fontface); |
| 8677 | 4174 | imhtml->edit.fontface = NULL; |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
4175 | |
| 8677 | 4176 | imhtml->edit.fontsize = 0; |
| 4177 | imhtml->edit.link = NULL; | |
| 4178 | ||
| 4179 | gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); | |
| 4180 | ||
| 4181 | ||
| 4182 | if (gtk_text_iter_is_end(&iter)) | |
| 4183 | tags = gtk_text_iter_get_toggled_tags(&iter, FALSE); | |
| 4184 | else | |
| 4185 | tags = gtk_text_iter_get_tags(&iter); | |
| 4186 | ||
| 4187 | for (l = tags; l != NULL; l = l->next) { | |
| 4188 | GtkTextTag *tag = GTK_TEXT_TAG(l->data); | |
| 4189 | ||
| 4190 | if (tag->name) { | |
| 4191 | if (strcmp(tag->name, "BOLD") == 0) | |
| 4192 | imhtml->edit.bold = TRUE; | |
|
13138
4d3bd039da3e
[gaim-migrate @ 15499]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13137
diff
changeset
|
4193 | else if (strcmp(tag->name, "ITALICS") == 0) |
| 8677 | 4194 | imhtml->edit.italic = TRUE; |
|
13138
4d3bd039da3e
[gaim-migrate @ 15499]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13137
diff
changeset
|
4195 | else if (strcmp(tag->name, "UNDERLINE") == 0) |
| 8677 | 4196 | imhtml->edit.underline = TRUE; |
|
13138
4d3bd039da3e
[gaim-migrate @ 15499]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13137
diff
changeset
|
4197 | else if (strcmp(tag->name, "STRIKE") == 0) |
| 9924 | 4198 | imhtml->edit.strike = TRUE; |
|
13138
4d3bd039da3e
[gaim-migrate @ 15499]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13137
diff
changeset
|
4199 | else if (strncmp(tag->name, "FORECOLOR ", 10) == 0) |
| 8677 | 4200 | imhtml->edit.forecolor = g_strdup(&(tag->name)[10]); |
|
13138
4d3bd039da3e
[gaim-migrate @ 15499]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13137
diff
changeset
|
4201 | else if (strncmp(tag->name, "BACKCOLOR ", 10) == 0) |
| 8677 | 4202 | imhtml->edit.backcolor = g_strdup(&(tag->name)[10]); |
|
13138
4d3bd039da3e
[gaim-migrate @ 15499]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13137
diff
changeset
|
4203 | else if (strncmp(tag->name, "FONT FACE ", 10) == 0) |
| 8677 | 4204 | imhtml->edit.fontface = g_strdup(&(tag->name)[10]); |
|
13138
4d3bd039da3e
[gaim-migrate @ 15499]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13137
diff
changeset
|
4205 | else if (strncmp(tag->name, "FONT SIZE ", 10) == 0) |
| 8677 | 4206 | imhtml->edit.fontsize = strtol(&(tag->name)[10], NULL, 10); |
|
13138
4d3bd039da3e
[gaim-migrate @ 15499]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13137
diff
changeset
|
4207 | else if ((strncmp(tag->name, "LINK ", 5) == 0) && !gtk_text_iter_is_end(&iter)) |
| 8677 | 4208 | imhtml->edit.link = tag; |
| 4209 | } | |
| 4210 | } | |
| 4211 | ||
| 4212 | g_slist_free(tags); | |
| 4213 | } | |
| 4214 | ||
|
12605
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4215 | static void imhtml_emit_signal_for_format(GtkIMHtml *imhtml, GtkIMHtmlButtons button) |
|
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4216 | { |
|
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4217 | GObject *object; |
|
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4218 | |
|
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4219 | g_return_if_fail(imhtml != NULL); |
|
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4220 | |
|
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4221 | object = g_object_ref(G_OBJECT(imhtml)); |
|
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4222 | g_signal_emit(object, signals[TOGGLE_FORMAT], 0, button); |
|
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4223 | g_object_unref(object); |
|
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4224 | } |
|
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4225 | |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4226 | static void imhtml_toggle_bold(GtkIMHtml *imhtml) |
| 8061 | 4227 | { |
| 8677 | 4228 | GtkTextIter start, end; |
| 4229 | ||
| 4230 | imhtml->edit.bold = !imhtml->edit.bold; | |
| 4231 | ||
| 4232 | if (imhtml->wbfo) { | |
| 4233 | gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 4234 | if (imhtml->edit.bold) | |
| 4235 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | |
| 4236 | else | |
| 4237 | gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | |
|
11276
aec923529d31
[gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents:
11275
diff
changeset
|
4238 | } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
| 8677 | 4239 | if (imhtml->edit.bold) |
| 4240 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | |
| 4241 | else | |
| 4242 | gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | |
|
11276
aec923529d31
[gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents:
11275
diff
changeset
|
4243 | |
| 8061 | 4244 | } |
| 4245 | } | |
| 4246 | ||
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4247 | void gtk_imhtml_toggle_bold(GtkIMHtml *imhtml) |
| 8061 | 4248 | { |
|
12605
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4249 | imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_BOLD); |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4250 | } |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4251 | |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4252 | static void imhtml_toggle_italic(GtkIMHtml *imhtml) |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4253 | { |
| 8677 | 4254 | GtkTextIter start, end; |
| 4255 | ||
| 4256 | imhtml->edit.italic = !imhtml->edit.italic; | |
| 4257 | ||
| 4258 | if (imhtml->wbfo) { | |
| 4259 | gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 4260 | if (imhtml->edit.italic) | |
| 4261 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); | |
| 4262 | else | |
| 4263 | gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); | |
|
11276
aec923529d31
[gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents:
11275
diff
changeset
|
4264 | } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
|
aec923529d31
[gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents:
11275
diff
changeset
|
4265 | if (imhtml->edit.italic) |
| 8677 | 4266 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); |
| 4267 | else | |
| 4268 | gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); | |
| 8061 | 4269 | } |
| 4270 | } | |
| 4271 | ||
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4272 | void gtk_imhtml_toggle_italic(GtkIMHtml *imhtml) |
| 8061 | 4273 | { |
|
12605
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4274 | imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_ITALIC); |
|
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4275 | } |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4276 | |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4277 | static void imhtml_toggle_underline(GtkIMHtml *imhtml) |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4278 | { |
| 8677 | 4279 | GtkTextIter start, end; |
| 4280 | ||
| 4281 | imhtml->edit.underline = !imhtml->edit.underline; | |
| 4282 | ||
| 4283 | if (imhtml->wbfo) { | |
| 4284 | gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 4285 | if (imhtml->edit.underline) | |
| 4286 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); | |
| 4287 | else | |
| 4288 | gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); | |
|
11276
aec923529d31
[gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents:
11275
diff
changeset
|
4289 | } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
|
aec923529d31
[gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents:
11275
diff
changeset
|
4290 | if (imhtml->edit.underline) |
| 8677 | 4291 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); |
| 4292 | else | |
| 4293 | gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); | |
| 8061 | 4294 | } |
| 4295 | } | |
| 4296 | ||
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4297 | void gtk_imhtml_toggle_underline(GtkIMHtml *imhtml) |
| 9924 | 4298 | { |
|
12605
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4299 | imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_UNDERLINE); |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4300 | } |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4301 | |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4302 | static void imhtml_toggle_strike(GtkIMHtml *imhtml) |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4303 | { |
| 9924 | 4304 | GtkTextIter start, end; |
| 4305 | ||
| 4306 | imhtml->edit.strike = !imhtml->edit.strike; | |
| 4307 | ||
| 4308 | if (imhtml->wbfo) { | |
| 4309 | gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 4310 | if (imhtml->edit.strike) | |
| 4311 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); | |
| 4312 | else | |
| 4313 | gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); | |
|
11276
aec923529d31
[gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents:
11275
diff
changeset
|
4314 | } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
|
aec923529d31
[gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents:
11275
diff
changeset
|
4315 | if (imhtml->edit.strike) |
| 9924 | 4316 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); |
| 4317 | else | |
| 4318 | gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); | |
| 4319 | } | |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4320 | } |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4321 | |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4322 | void gtk_imhtml_toggle_strike(GtkIMHtml *imhtml) |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4323 | { |
|
12605
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4324 | imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_STRIKE); |
| 9924 | 4325 | } |
| 4326 | ||
| 8061 | 4327 | void gtk_imhtml_font_set_size(GtkIMHtml *imhtml, gint size) |
| 4328 | { | |
| 9025 | 4329 | GObject *object; |
| 8677 | 4330 | GtkTextIter start, end; |
| 8061 | 4331 | |
| 4332 | imhtml->edit.fontsize = size; | |
| 4333 | ||
| 8677 | 4334 | if (imhtml->wbfo) { |
| 4335 | gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 4336 | remove_font_size(imhtml, &start, &end, TRUE); | |
| 4337 | gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 4338 | find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
|
11276
aec923529d31
[gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents:
11275
diff
changeset
|
4339 | } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
| 8677 | 4340 | remove_font_size(imhtml, &start, &end, FALSE); |
| 4341 | gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 4342 | find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
| 8061 | 4343 | } |
| 8677 | 4344 | |
| 9025 | 4345 | object = g_object_ref(G_OBJECT(imhtml)); |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4346 | g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_SHRINK | GTK_IMHTML_GROW); |
| 9025 | 4347 | g_object_unref(object); |
| 8061 | 4348 | } |
| 4349 | ||
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4350 | static void imhtml_font_shrink(GtkIMHtml *imhtml) |
| 8061 | 4351 | { |
| 8677 | 4352 | GtkTextIter start, end; |
| 4353 | ||
| 8061 | 4354 | if (imhtml->edit.fontsize == 1) |
| 4355 | return; | |
| 4356 | ||
| 8677 | 4357 | if (!imhtml->edit.fontsize) |
| 4358 | imhtml->edit.fontsize = 2; | |
| 4359 | else | |
| 4360 | imhtml->edit.fontsize--; | |
| 4361 | ||
| 4362 | if (imhtml->wbfo) { | |
| 4363 | gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 4364 | remove_font_size(imhtml, &start, &end, TRUE); | |
| 4365 | gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 4366 | find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
|
11276
aec923529d31
[gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents:
11275
diff
changeset
|
4367 | } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
| 8677 | 4368 | remove_font_size(imhtml, &start, &end, FALSE); |
| 4369 | gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 4370 | find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
| 8061 | 4371 | } |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4372 | } |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4373 | |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4374 | void gtk_imhtml_font_shrink(GtkIMHtml *imhtml) |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4375 | { |
|
12605
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4376 | imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_SHRINK); |
| 8061 | 4377 | } |
| 4378 | ||
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4379 | static void imhtml_font_grow(GtkIMHtml *imhtml) |
| 8061 | 4380 | { |
| 8677 | 4381 | GtkTextIter start, end; |
| 4382 | ||
| 8061 | 4383 | if (imhtml->edit.fontsize == MAX_FONT_SIZE) |
| 4384 | return; | |
| 4385 | ||
| 8677 | 4386 | if (!imhtml->edit.fontsize) |
| 4387 | imhtml->edit.fontsize = 4; | |
| 4388 | else | |
| 4389 | imhtml->edit.fontsize++; | |
| 4390 | ||
| 4391 | if (imhtml->wbfo) { | |
| 4392 | gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 4393 | remove_font_size(imhtml, &start, &end, TRUE); | |
| 4394 | gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 4395 | find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
|
11276
aec923529d31
[gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents:
11275
diff
changeset
|
4396 | } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
| 8677 | 4397 | remove_font_size(imhtml, &start, &end, FALSE); |
| 4398 | gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 4399 | find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
| 8061 | 4400 | } |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4401 | } |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4402 | |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4403 | void gtk_imhtml_font_grow(GtkIMHtml *imhtml) |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4404 | { |
|
12605
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4405 | imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_GROW); |
| 8061 | 4406 | } |
| 4407 | ||
|
13225
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4408 | 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
|
4409 | void (*remove_func)(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo), |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4410 | GtkTextTag *(find_func)(GtkIMHtml *imhtml, gchar *color), GtkIMHtmlButtons button) |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4411 | { |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4412 | GObject *object; |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4413 | GtkTextIter start; |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4414 | GtkTextIter end; |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4415 | |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4416 | g_free(*edit_field); |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4417 | *edit_field = NULL; |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4418 | |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4419 | if (value && strcmp(value, "") != 0) |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4420 | { |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4421 | *edit_field = g_strdup(value); |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4422 | |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4423 | if (imhtml->wbfo) |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4424 | { |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4425 | gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4426 | remove_func(imhtml, &start, &end, TRUE); |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4427 | gtk_text_buffer_apply_tag(imhtml->text_buffer, |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4428 | find_func(imhtml, *edit_field), &start, &end); |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4429 | } |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4430 | else |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4431 | { |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4432 | gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4433 | gtk_text_buffer_get_mark(imhtml->text_buffer, "insert")); |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4434 | if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4435 | { |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4436 | remove_func(imhtml, &start, &end, FALSE); |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4437 | gtk_text_buffer_apply_tag(imhtml->text_buffer, |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4438 | find_func(imhtml, |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4439 | *edit_field), |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4440 | &start, &end); |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4441 | } |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4442 | } |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4443 | } |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4444 | else |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4445 | { |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4446 | if (imhtml->wbfo) |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4447 | { |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4448 | gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4449 | remove_func(imhtml, &start, &end, TRUE); |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4450 | } |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4451 | else |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4452 | { |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4453 | if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4454 | remove_func(imhtml, &start, &end, TRUE); |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4455 | } |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4456 | } |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4457 | |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4458 | object = g_object_ref(G_OBJECT(imhtml)); |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4459 | g_signal_emit(object, signals[TOGGLE_FORMAT], 0, button); |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4460 | g_object_unref(object); |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4461 | |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4462 | return *edit_field != NULL; |
| 10776 | 4463 | } |
| 4464 | ||
| 8061 | 4465 | gboolean gtk_imhtml_toggle_forecolor(GtkIMHtml *imhtml, const char *color) |
| 4466 | { | |
|
13225
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4467 | return gtk_imhtml_toggle_str_tag(imhtml, color, &imhtml->edit.forecolor, |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4468 | remove_font_forecolor, find_font_forecolor_tag, |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4469 | GTK_IMHTML_FORECOLOR); |
| 8061 | 4470 | } |
| 4471 | ||
| 4472 | gboolean gtk_imhtml_toggle_backcolor(GtkIMHtml *imhtml, const char *color) | |
| 4473 | { | |
|
13225
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4474 | return gtk_imhtml_toggle_str_tag(imhtml, color, &imhtml->edit.backcolor, |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4475 | remove_font_backcolor, find_font_backcolor_tag, |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4476 | GTK_IMHTML_BACKCOLOR); |
| 10776 | 4477 | } |
| 4478 | ||
| 4479 | gboolean gtk_imhtml_toggle_background(GtkIMHtml *imhtml, const char *color) | |
| 4480 | { | |
|
13225
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4481 | return gtk_imhtml_toggle_str_tag(imhtml, color, &imhtml->edit.background, |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4482 | remove_font_background, find_font_background_tag, |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4483 | GTK_IMHTML_BACKGROUND); |
| 8061 | 4484 | } |
| 4485 | ||
| 4486 | gboolean gtk_imhtml_toggle_fontface(GtkIMHtml *imhtml, const char *face) | |
| 4487 | { | |
|
13225
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4488 | return gtk_imhtml_toggle_str_tag(imhtml, face, &imhtml->edit.fontface, |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4489 | remove_font_face, find_font_face_tag, |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4490 | GTK_IMHTML_FACE); |
| 8061 | 4491 | } |
| 4492 | ||
| 8677 | 4493 | void gtk_imhtml_toggle_link(GtkIMHtml *imhtml, const char *url) |
| 8061 | 4494 | { |
| 9025 | 4495 | GObject *object; |
| 8677 | 4496 | GtkTextIter start, end; |
| 4497 | GtkTextTag *linktag; | |
| 4498 | static guint linkno = 0; | |
| 4499 | gchar str[48]; | |
| 9007 | 4500 | GdkColor *color = NULL; |
| 8677 | 4501 | |
| 4502 | imhtml->edit.link = NULL; | |
| 4503 | ||
| 4504 | if (url) { | |
| 4505 | g_snprintf(str, sizeof(str), "LINK %d", linkno++); | |
| 4506 | str[47] = '\0'; | |
| 4507 | ||
| 9007 | 4508 | gtk_widget_style_get(GTK_WIDGET(imhtml), "hyperlink-color", &color, NULL); |
| 9008 | 4509 | if (color) { |
| 9007 | 4510 | imhtml->edit.link = linktag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground-gdk", color, "underline", PANGO_UNDERLINE_SINGLE, NULL); |
| 9008 | 4511 | gdk_color_free(color); |
| 4512 | } else { | |
| 9007 | 4513 | imhtml->edit.link = linktag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL); |
| 9008 | 4514 | } |
| 8677 | 4515 | g_object_set_data_full(G_OBJECT(linktag), "link_url", g_strdup(url), g_free); |
| 4516 | g_signal_connect(G_OBJECT(linktag), "event", G_CALLBACK(tag_event), NULL); | |
| 4517 | ||
|
11276
aec923529d31
[gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents:
11275
diff
changeset
|
4518 | if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
| 8677 | 4519 | remove_font_link(imhtml, &start, &end, FALSE); |
| 4520 | gtk_text_buffer_apply_tag(imhtml->text_buffer, linktag, &start, &end); | |
| 4521 | } | |
| 4522 | } | |
| 9025 | 4523 | |
| 4524 | object = g_object_ref(G_OBJECT(imhtml)); | |
| 4525 | g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_LINK); | |
| 4526 | g_object_unref(object); | |
| 8677 | 4527 | } |
| 4528 | ||
| 4529 | void gtk_imhtml_insert_link(GtkIMHtml *imhtml, GtkTextMark *mark, const char *url, const char *text) | |
| 4530 | { | |
| 8061 | 4531 | GtkTextIter iter; |
| 8677 | 4532 | |
| 9599 | 4533 | if (gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) |
| 4534 | gtk_text_buffer_delete_selection(imhtml->text_buffer, TRUE, TRUE); | |
| 4535 | ||
| 8677 | 4536 | gtk_imhtml_toggle_link(imhtml, url); |
| 8061 | 4537 | gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); |
| 8677 | 4538 | gtk_text_buffer_insert(imhtml->text_buffer, &iter, text, -1); |
| 4539 | gtk_imhtml_toggle_link(imhtml, NULL); | |
| 8061 | 4540 | } |
| 4541 | ||
| 4542 | void gtk_imhtml_insert_smiley(GtkIMHtml *imhtml, const char *sml, char *smiley) | |
| 4543 | { | |
| 8677 | 4544 | GtkTextMark *mark; |
| 8061 | 4545 | GtkTextIter iter; |
| 8677 | 4546 | |
|
11750
63f951281392
[gaim-migrate @ 14041]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11701
diff
changeset
|
4547 | if (gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) |
|
63f951281392
[gaim-migrate @ 14041]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11701
diff
changeset
|
4548 | gtk_text_buffer_delete_selection(imhtml->text_buffer, TRUE, TRUE); |
|
63f951281392
[gaim-migrate @ 14041]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11701
diff
changeset
|
4549 | |
| 8677 | 4550 | mark = gtk_text_buffer_get_insert(imhtml->text_buffer); |
| 4551 | ||
| 4552 | gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); | |
| 4553 | gtk_imhtml_insert_smiley_at_iter(imhtml, sml, smiley, &iter); | |
| 4554 | } | |
| 4555 | ||
| 13552 | 4556 | static gboolean |
| 4557 | image_expose(GtkWidget *widget, GdkEventExpose *event, gpointer user_data) | |
| 4558 | { | |
| 4559 | GTK_WIDGET_CLASS(GTK_WIDGET_GET_CLASS(widget))->expose_event(widget, event); | |
| 4560 | ||
| 4561 | return TRUE; | |
| 4562 | } | |
| 4563 | ||
|
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
|
4564 | /* In case the smiley gets removed from the imhtml before it gets removed from the queue */ |
|
aa5b9456e258
Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents:
16291
diff
changeset
|
4565 | static void animated_smiley_destroy_cb(GtkObject *widget, GtkIMHtml *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
|
4566 | { |
|
aa5b9456e258
Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents:
16291
diff
changeset
|
4567 | 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
|
4568 | 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
|
4569 | 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
|
4570 | 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
|
4571 | 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
|
4572 | 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
|
4573 | 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
|
4574 | 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
|
4575 | } |
|
aa5b9456e258
Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents:
16291
diff
changeset
|
4576 | 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
|
4577 | } |
|
aa5b9456e258
Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents:
16291
diff
changeset
|
4578 | } |
|
aa5b9456e258
Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents:
16291
diff
changeset
|
4579 | |
| 8677 | 4580 | void gtk_imhtml_insert_smiley_at_iter(GtkIMHtml *imhtml, const char *sml, char *smiley, GtkTextIter *iter) |
| 4581 | { | |
| 8061 | 4582 | GdkPixbuf *pixbuf = NULL; |
| 4583 | GdkPixbufAnimation *annipixbuf = NULL; | |
| 4584 | 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
|
4585 | GtkTextChildAnchor *anchor = NULL; |
| 15884 | 4586 | char *unescaped = purple_unescape_html(smiley); |
|
11525
1d06283bdcc9
[gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11485
diff
changeset
|
4587 | GtkIMHtmlSmiley *imhtml_smiley = gtk_imhtml_smiley_get(imhtml, sml, unescaped); |
|
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
|
4588 | GtkWidget *ebox = NULL; |
| 8061 | 4589 | |
| 10526 | 4590 | if (imhtml->format_functions & GTK_IMHTML_SMILEY) { |
|
10522
d505522bcc93
[gaim-migrate @ 11838]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10504
diff
changeset
|
4591 | annipixbuf = gtk_smiley_tree_image(imhtml, sml, unescaped); |
| 10526 | 4592 | if (annipixbuf) { |
| 4593 | if (gdk_pixbuf_animation_is_static_image(annipixbuf)) { | |
|
10522
d505522bcc93
[gaim-migrate @ 11838]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10504
diff
changeset
|
4594 | pixbuf = gdk_pixbuf_animation_get_static_image(annipixbuf); |
| 10526 | 4595 | if (pixbuf) |
|
10522
d505522bcc93
[gaim-migrate @ 11838]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10504
diff
changeset
|
4596 | icon = gtk_image_new_from_pixbuf(pixbuf); |
|
d505522bcc93
[gaim-migrate @ 11838]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10504
diff
changeset
|
4597 | } else { |
|
d505522bcc93
[gaim-migrate @ 11838]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10504
diff
changeset
|
4598 | 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
|
4599 | 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
|
4600 | 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
|
4601 | GdkPixbufAnimation *anim = gtk_image_get_animation(image); |
|
aa5b9456e258
Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents:
16291
diff
changeset
|
4602 | 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
|
4603 | GdkPixbuf *pb = gdk_pixbuf_animation_get_static_image(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
|
4604 | gtk_image_set_from_pixbuf(image, pb); |
|
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
|
4605 | g_object_unref(G_OBJECT(pb)); |
|
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
|
4606 | } |
|
aa5b9456e258
Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents:
16291
diff
changeset
|
4607 | } 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
|
4608 | 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
|
4609 | } |
|
aa5b9456e258
Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents:
16291
diff
changeset
|
4610 | 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
|
4611 | g_queue_push_tail(imhtml->animations, icon); |
|
10522
d505522bcc93
[gaim-migrate @ 11838]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10504
diff
changeset
|
4612 | } |
| 8061 | 4613 | } |
| 4614 | } | |
| 4615 | ||
|
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
|
4616 | 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
|
4617 | ebox = gtk_event_box_new(); |
| 17406 | 4618 | #if GTK_CHECK_VERSION(2,4,0) |
|
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
|
4619 | gtk_event_box_set_visible_window(GTK_EVENT_BOX(ebox), FALSE); |
| 17406 | 4620 | #endif |
|
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
|
4621 | 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
|
4622 | } |
|
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
|
4623 | |
| 8061 | 4624 | if (icon) { |
| 8890 | 4625 | anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); |
| 4626 | g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_plaintext", g_strdup(unescaped), g_free); | |
| 4627 | g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_htmltext", g_strdup(smiley), g_free); | |
| 4628 | ||
| 13552 | 4629 | /* This catches the expose events generated by animated |
| 4630 | * images, and ensures that they are handled by the image | |
| 4631 | * itself, without propagating to the textview and causing | |
| 4632 | * a complete refresh */ | |
| 4633 | g_signal_connect(G_OBJECT(icon), "expose-event", G_CALLBACK(image_expose), NULL); | |
| 4634 | ||
| 8061 | 4635 | 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
|
4636 | 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
|
4637 | 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
|
4638 | gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), ebox ? ebox : icon, anchor); |
|
11525
1d06283bdcc9
[gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11485
diff
changeset
|
4639 | } 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
|
4640 | anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); |
|
1d06283bdcc9
[gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11485
diff
changeset
|
4641 | imhtml_smiley->anchors = g_slist_append(imhtml_smiley->anchors, 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
|
4642 | 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
|
4643 | 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
|
4644 | 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
|
4645 | gtk_widget_show(img); |
|
18543
c590aed61aa4
Show tooltip for smileys. Fixes #1981.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18371
diff
changeset
|
4646 | g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_plaintext", g_strdup(unescaped), 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
|
4647 | 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
|
4648 | } |
| 8890 | 4649 | } else { |
| 4650 | gtk_text_buffer_insert(imhtml->text_buffer, iter, smiley, -1); | |
| 8061 | 4651 | } |
| 8890 | 4652 | |
|
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
|
4653 | 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
|
4654 | 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
|
4655 | } |
|
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
|
4656 | |
| 8890 | 4657 | g_free(unescaped); |
| 8061 | 4658 | } |
| 4659 | ||
| 8962 | 4660 | void gtk_imhtml_insert_image_at_iter(GtkIMHtml *imhtml, int id, GtkTextIter *iter) |
| 4661 | { | |
|
18151
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
4662 | GdkPixbufAnimation *anim = NULL; |
| 8962 | 4663 | const char *filename = NULL; |
| 4664 | gpointer image; | |
| 4665 | GdkRectangle rect; | |
| 4666 | GtkIMHtmlScalable *scalable = NULL; | |
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
4667 | struct scalable_data *sd; |
| 8962 | 4668 | int minus; |
| 4669 | ||
| 4670 | if (!imhtml->funcs || !imhtml->funcs->image_get || | |
| 4671 | !imhtml->funcs->image_get_size || !imhtml->funcs->image_get_data || | |
| 4672 | !imhtml->funcs->image_get_filename || !imhtml->funcs->image_ref || | |
| 4673 | !imhtml->funcs->image_unref) | |
| 4674 | return; | |
| 4675 | ||
| 4676 | image = imhtml->funcs->image_get(id); | |
| 4677 | ||
| 4678 | if (image) { | |
| 4679 | gpointer data; | |
| 4680 | size_t len; | |
| 4681 | ||
| 4682 | data = imhtml->funcs->image_get_data(image); | |
| 4683 | len = imhtml->funcs->image_get_size(image); | |
| 4684 | ||
| 4685 | if (data && len) { | |
| 4686 | GdkPixbufLoader *loader = gdk_pixbuf_loader_new(); | |
| 4687 | gdk_pixbuf_loader_write(loader, data, len, NULL); | |
|
12230
2f327bccf63b
[gaim-migrate @ 14532]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12229
diff
changeset
|
4688 | 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
|
4689 | 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
|
4690 | if (anim) |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
4691 | g_object_ref(G_OBJECT(anim)); |
| 9337 | 4692 | g_object_unref(G_OBJECT(loader)); |
| 8962 | 4693 | } |
| 4694 | ||
| 4695 | } | |
| 4696 | ||
|
18151
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
4697 | if (anim) { |
|
11299
06bb44ed0cf3
[gaim-migrate @ 13499]
Richard Laager <rlaager@pidgin.im>
parents:
11276
diff
changeset
|
4698 | struct im_image_data *t = g_new(struct im_image_data, 1); |
| 8962 | 4699 | filename = imhtml->funcs->image_get_filename(image); |
| 4700 | imhtml->funcs->image_ref(id); | |
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
4701 | t->id = id; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
4702 | 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
|
4703 | 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
|
4704 | 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
|
4705 | g_object_unref(G_OBJECT(anim)); |
| 8962 | 4706 | } else { |
|
18151
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
4707 | GdkPixbuf *pixbuf; |
| 8962 | 4708 | pixbuf = gtk_widget_render_icon(GTK_WIDGET(imhtml), GTK_STOCK_MISSING_IMAGE, |
| 4709 | 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
|
4710 | 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
|
4711 | g_object_unref(G_OBJECT(pixbuf)); |
| 8962 | 4712 | } |
| 4713 | ||
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
4714 | 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
|
4715 | sd->scalable = scalable; |
|
11233
28c0f184a2d4
[gaim-migrate @ 13373]
Daniel Atallah <datallah@pidgin.im>
parents:
11224
diff
changeset
|
4716 | sd->mark = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, iter, TRUE); |
| 8962 | 4717 | gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); |
| 4718 | scalable->add_to(scalable, imhtml, iter); | |
| 4719 | minus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(imhtml)) + | |
| 4720 | gtk_text_view_get_right_margin(GTK_TEXT_VIEW(imhtml)); | |
| 4721 | scalable->scale(scalable, rect.width - minus, rect.height); | |
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
4722 | imhtml->scalables = g_list_append(imhtml->scalables, sd); |
| 8962 | 4723 | } |
| 4724 | ||
| 8677 | 4725 | static const gchar *tag_to_html_start(GtkTextTag *tag) |
| 8061 | 4726 | { |
| 8677 | 4727 | const gchar *name; |
| 4728 | static gchar buf[1024]; | |
| 4729 | ||
| 4730 | name = tag->name; | |
| 4731 | g_return_val_if_fail(name != NULL, ""); | |
| 4732 | ||
| 4733 | if (strcmp(name, "BOLD") == 0) { | |
| 4734 | return "<b>"; | |
| 4735 | } else if (strcmp(name, "ITALICS") == 0) { | |
| 4736 | return "<i>"; | |
| 4737 | } else if (strcmp(name, "UNDERLINE") == 0) { | |
| 4738 | return "<u>"; | |
| 9924 | 4739 | } else if (strcmp(name, "STRIKE") == 0) { |
| 4740 | return "<s>"; | |
| 8677 | 4741 | } else if (strncmp(name, "LINK ", 5) == 0) { |
| 4742 | char *tmp = g_object_get_data(G_OBJECT(tag), "link_url"); | |
| 4743 | if (tmp) { | |
| 4744 | g_snprintf(buf, sizeof(buf), "<a href=\"%s\">", tmp); | |
| 4745 | buf[sizeof(buf)-1] = '\0'; | |
| 4746 | return buf; | |
| 4747 | } else { | |
| 4748 | return ""; | |
| 4749 | } | |
| 4750 | } else if (strncmp(name, "FORECOLOR ", 10) == 0) { | |
| 4751 | g_snprintf(buf, sizeof(buf), "<font color=\"%s\">", &name[10]); | |
| 4752 | return buf; | |
| 4753 | } else if (strncmp(name, "BACKCOLOR ", 10) == 0) { | |
| 4754 | g_snprintf(buf, sizeof(buf), "<font back=\"%s\">", &name[10]); | |
| 4755 | return buf; | |
| 10776 | 4756 | } else if (strncmp(name, "BACKGROUND ", 10) == 0) { |
| 4757 | g_snprintf(buf, sizeof(buf), "<body bgcolor=\"%s\">", &name[11]); | |
| 4758 | return buf; | |
| 8677 | 4759 | } else if (strncmp(name, "FONT FACE ", 10) == 0) { |
| 4760 | g_snprintf(buf, sizeof(buf), "<font face=\"%s\">", &name[10]); | |
| 4761 | return buf; | |
| 4762 | } else if (strncmp(name, "FONT SIZE ", 10) == 0) { | |
| 4763 | g_snprintf(buf, sizeof(buf), "<font size=\"%s\">", &name[10]); | |
| 4764 | return buf; | |
| 4765 | } else { | |
| 4766 | return ""; | |
| 4767 | } | |
| 8061 | 4768 | } |
| 4769 | ||
| 8677 | 4770 | static const gchar *tag_to_html_end(GtkTextTag *tag) |
| 8061 | 4771 | { |
| 8677 | 4772 | const gchar *name; |
| 4773 | ||
| 4774 | name = tag->name; | |
| 4775 | g_return_val_if_fail(name != NULL, ""); | |
| 4776 | ||
| 4777 | if (strcmp(name, "BOLD") == 0) { | |
| 4778 | return "</b>"; | |
| 4779 | } else if (strcmp(name, "ITALICS") == 0) { | |
| 4780 | return "</i>"; | |
| 4781 | } else if (strcmp(name, "UNDERLINE") == 0) { | |
| 4782 | return "</u>"; | |
| 9924 | 4783 | } else if (strcmp(name, "STRIKE") == 0) { |
| 4784 | return "</s>"; | |
| 8677 | 4785 | } else if (strncmp(name, "LINK ", 5) == 0) { |
| 4786 | return "</a>"; | |
| 4787 | } else if (strncmp(name, "FORECOLOR ", 10) == 0) { | |
| 4788 | return "</font>"; | |
| 4789 | } else if (strncmp(name, "BACKCOLOR ", 10) == 0) { | |
| 4790 | return "</font>"; | |
| 10776 | 4791 | } else if (strncmp(name, "BACKGROUND ", 10) == 0) { |
| 4792 | return "</body>"; | |
| 8677 | 4793 | } else if (strncmp(name, "FONT FACE ", 10) == 0) { |
| 4794 | return "</font>"; | |
| 4795 | } else if (strncmp(name, "FONT SIZE ", 10) == 0) { | |
| 4796 | return "</font>"; | |
| 4797 | } else { | |
| 4798 | return ""; | |
| 4799 | } | |
| 4800 | } | |
| 4801 | ||
| 4802 | static gboolean tag_ends_here(GtkTextTag *tag, GtkTextIter *iter, GtkTextIter *niter) | |
| 4803 | { | |
| 4804 | return ((gtk_text_iter_has_tag(iter, GTK_TEXT_TAG(tag)) && | |
| 4805 | !gtk_text_iter_has_tag(niter, GTK_TEXT_TAG(tag))) || | |
| 4806 | gtk_text_iter_is_end(niter)); | |
| 8061 | 4807 | } |
| 4808 | ||
| 4809 | /* Basic notion here: traverse through the text buffer one-by-one, non-character elements, such | |
| 4810 | * as smileys and IM images are represented by the Unicode "unknown" character. Handle them. Else | |
| 8677 | 4811 | * check for tags that are toggled on, insert their html form, and push them on the queue. Then insert |
| 4812 | * 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
|
4813 | * Finally, replace <, >, &, and " with their HTML equivalent. |
| 8677 | 4814 | */ |
| 8061 | 4815 | char *gtk_imhtml_get_markup_range(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) |
| 4816 | { | |
| 4817 | gunichar c; | |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4818 | GtkTextIter iter, next_iter, non_neutral_iter; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4819 | gboolean is_rtl_message = FALSE; |
| 8061 | 4820 | GString *str = g_string_new(""); |
| 8677 | 4821 | GSList *tags, *sl; |
| 4822 | GQueue *q, *r; | |
| 4823 | GtkTextTag *tag; | |
| 4824 | ||
| 4825 | q = g_queue_new(); | |
| 4826 | r = g_queue_new(); | |
| 4827 | ||
| 8061 | 4828 | |
| 4829 | gtk_text_iter_order(start, end); | |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4830 | non_neutral_iter = next_iter = iter = *start; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4831 | gtk_text_iter_forward_char(&next_iter); |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4832 | |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4833 | /* Bi-directional text support */ |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4834 | /* 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
|
4835 | #ifdef HAVE_PANGO14 |
| 16144 | 4836 | 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
|
4837 | && gtk_text_iter_forward_char(&non_neutral_iter)); |
| 16144 | 4838 | 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
|
4839 | is_rtl_message = TRUE; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4840 | 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
|
4841 | } |
|
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
|
4842 | #endif |
| 8677 | 4843 | |
| 9071 | 4844 | /* First add the tags that are already in progress (we don't care about non-printing tags)*/ |
| 8677 | 4845 | tags = gtk_text_iter_get_tags(start); |
| 4846 | ||
| 4847 | for (sl = tags; sl; sl = sl->next) { | |
| 4848 | tag = sl->data; | |
| 4849 | if (!gtk_text_iter_toggles_tag(start, GTK_TEXT_TAG(tag))) { | |
| 9071 | 4850 | if (strlen(tag_to_html_end(tag)) > 0) |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
4851 | g_string_append(str, tag_to_html_start(tag)); |
| 8677 | 4852 | g_queue_push_tail(q, tag); |
| 8061 | 4853 | } |
| 4854 | } | |
| 8677 | 4855 | g_slist_free(tags); |
| 8061 | 4856 | |
| 4857 | while ((c = gtk_text_iter_get_char(&iter)) != 0 && !gtk_text_iter_equal(&iter, end)) { | |
| 8677 | 4858 | |
| 4859 | tags = gtk_text_iter_get_tags(&iter); | |
| 4860 | ||
| 4861 | for (sl = tags; sl; sl = sl->next) { | |
| 4862 | tag = sl->data; | |
| 4863 | if (gtk_text_iter_begins_tag(&iter, GTK_TEXT_TAG(tag))) { | |
| 9071 | 4864 | if (strlen(tag_to_html_end(tag)) > 0) |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
4865 | g_string_append(str, tag_to_html_start(tag)); |
| 8677 | 4866 | g_queue_push_tail(q, tag); |
| 4867 | } | |
| 4868 | } | |
| 4869 | ||
| 4870 | ||
| 8061 | 4871 | if (c == 0xFFFC) { |
| 4872 | GtkTextChildAnchor* anchor = gtk_text_iter_get_child_anchor(&iter); | |
| 9071 | 4873 | if (anchor) { |
| 4874 | char *text = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_htmltext"); | |
| 4875 | if (text) | |
| 4876 | str = g_string_append(str, text); | |
| 4877 | } | |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
4878 | } else if (c == '<') { |
| 8677 | 4879 | str = g_string_append(str, "<"); |
| 4880 | } else if (c == '>') { | |
| 4881 | str = g_string_append(str, ">"); | |
| 4882 | } else if (c == '&') { | |
| 4883 | str = g_string_append(str, "&"); | |
| 4884 | } else if (c == '"') { | |
| 4885 | str = g_string_append(str, """); | |
| 4886 | } else if (c == '\n') { | |
| 4887 | str = g_string_append(str, "<br>"); | |
| 8061 | 4888 | } else { |
| 8677 | 4889 | str = g_string_append_unichar(str, c); |
| 4890 | } | |
| 4891 | ||
| 4892 | tags = g_slist_reverse(tags); | |
| 4893 | for (sl = tags; sl; sl = sl->next) { | |
| 4894 | tag = sl->data; | |
| 9071 | 4895 | /** don't worry about non-printing tags ending */ |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4896 | if (tag_ends_here(tag, &iter, &next_iter) && strlen(tag_to_html_end(tag)) > 0) { |
| 8677 | 4897 | |
| 4898 | GtkTextTag *tmp; | |
| 4899 | ||
| 4900 | while ((tmp = g_queue_pop_tail(q)) != tag) { | |
| 4901 | if (tmp == NULL) | |
| 4902 | break; | |
| 4903 | ||
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4904 | if (!tag_ends_here(tmp, &iter, &next_iter) && strlen(tag_to_html_end(tmp)) > 0) |
| 8677 | 4905 | g_queue_push_tail(r, tmp); |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
4906 | g_string_append(str, tag_to_html_end(GTK_TEXT_TAG(tmp))); |
| 8677 | 4907 | } |
| 4908 | ||
| 4909 | if (tmp == NULL) | |
| 15884 | 4910 | purple_debug_warning("gtkimhtml", "empty queue, more closing tags than open tags!\n"); |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
4911 | else |
| 8677 | 4912 | g_string_append(str, tag_to_html_end(GTK_TEXT_TAG(tag))); |
| 4913 | ||
| 4914 | while ((tmp = g_queue_pop_head(r))) { | |
| 4915 | g_string_append(str, tag_to_html_start(GTK_TEXT_TAG(tmp))); | |
| 4916 | g_queue_push_tail(q, tmp); | |
| 8061 | 4917 | } |
| 4918 | } | |
| 4919 | } | |
| 8677 | 4920 | |
| 4921 | g_slist_free(tags); | |
| 8061 | 4922 | gtk_text_iter_forward_char(&iter); |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4923 | gtk_text_iter_forward_char(&next_iter); |
| 8061 | 4924 | } |
| 8677 | 4925 | |
| 4926 | while ((tag = g_queue_pop_tail(q))) | |
| 4927 | g_string_append(str, tag_to_html_end(GTK_TEXT_TAG(tag))); | |
| 4928 | ||
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4929 | /* Bi-directional text support - close tags */ |
| 16144 | 4930 | if (is_rtl_message) |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4931 | g_string_append(str, "</SPAN>"); |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4932 | |
| 8677 | 4933 | g_queue_free(q); |
| 4934 | g_queue_free(r); | |
| 8061 | 4935 | return g_string_free(str, FALSE); |
| 4936 | } | |
| 4937 | ||
| 8698 | 4938 | void gtk_imhtml_close_tags(GtkIMHtml *imhtml, GtkTextIter *iter) |
| 8061 | 4939 | { |
| 4940 | if (imhtml->edit.bold) | |
| 4941 | gtk_imhtml_toggle_bold(imhtml); | |
| 4942 | ||
| 4943 | if (imhtml->edit.italic) | |
| 4944 | gtk_imhtml_toggle_italic(imhtml); | |
| 4945 | ||
| 4946 | if (imhtml->edit.underline) | |
| 4947 | gtk_imhtml_toggle_underline(imhtml); | |
| 4948 | ||
| 9924 | 4949 | if (imhtml->edit.strike) |
| 4950 | gtk_imhtml_toggle_strike(imhtml); | |
| 4951 | ||
| 8061 | 4952 | if (imhtml->edit.forecolor) |
| 4953 | gtk_imhtml_toggle_forecolor(imhtml, NULL); | |
| 4954 | ||
| 4955 | if (imhtml->edit.backcolor) | |
| 4956 | gtk_imhtml_toggle_backcolor(imhtml, NULL); | |
| 4957 | ||
| 4958 | if (imhtml->edit.fontface) | |
| 4959 | gtk_imhtml_toggle_fontface(imhtml, NULL); | |
| 4960 | ||
| 8677 | 4961 | imhtml->edit.fontsize = 0; |
| 4962 | ||
| 8719 | 4963 | if (imhtml->edit.link) |
| 4964 | gtk_imhtml_toggle_link(imhtml, NULL); | |
| 8061 | 4965 | } |
| 4966 | ||
| 4967 | char *gtk_imhtml_get_markup(GtkIMHtml *imhtml) | |
| 4968 | { | |
| 4969 | GtkTextIter start, end; | |
| 4970 | ||
| 4971 | gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); | |
| 4972 | gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
| 4973 | return gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
| 4974 | } | |
| 4975 | ||
| 8677 | 4976 | char **gtk_imhtml_get_markup_lines(GtkIMHtml *imhtml) |
| 4977 | { | |
| 4978 | int i, j, lines; | |
| 4979 | GtkTextIter start, end; | |
| 4980 | char **ret; | |
| 4981 | ||
| 4982 | lines = gtk_text_buffer_get_line_count(imhtml->text_buffer); | |
| 4983 | ret = g_new0(char *, lines + 1); | |
| 4984 | gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); | |
| 4985 | end = start; | |
| 4986 | gtk_text_iter_forward_to_line_end(&end); | |
| 4987 | ||
| 4988 | for (i = 0, j = 0; i < lines; i++) { | |
| 9612 | 4989 | if (gtk_text_iter_get_char(&start) != '\n') { |
| 4990 | ret[j] = gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
| 4991 | if (ret[j] != NULL) | |
| 4992 | j++; | |
| 4993 | } | |
| 4994 | ||
| 8677 | 4995 | gtk_text_iter_forward_line(&start); |
| 4996 | end = start; | |
| 4997 | gtk_text_iter_forward_to_line_end(&end); | |
| 4998 | } | |
| 4999 | ||
| 5000 | return ret; | |
| 5001 | } | |
| 5002 | ||
| 5003 | char *gtk_imhtml_get_text(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *stop) | |
| 8061 | 5004 | { |
| 8519 | 5005 | GString *str = g_string_new(""); |
| 5006 | GtkTextIter iter, end; | |
| 5007 | gunichar c; | |
| 5008 | ||
| 8677 | 5009 | if (start == NULL) |
| 5010 | gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter); | |
| 5011 | else | |
| 5012 | iter = *start; | |
| 5013 | ||
| 5014 | if (stop == NULL) | |
| 5015 | gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
| 5016 | else | |
| 5017 | end = *stop; | |
| 5018 | ||
| 5019 | gtk_text_iter_order(&iter, &end); | |
| 8519 | 5020 | |
| 5021 | while ((c = gtk_text_iter_get_char(&iter)) != 0 && !gtk_text_iter_equal(&iter, &end)) { | |
| 5022 | if (c == 0xFFFC) { | |
| 8677 | 5023 | GtkTextChildAnchor* anchor; |
| 5024 | char *text = NULL; | |
| 5025 | ||
| 5026 | anchor = gtk_text_iter_get_child_anchor(&iter); | |
| 5027 | if (anchor) | |
| 8698 | 5028 | text = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_plaintext"); |
| 8677 | 5029 | if (text) |
| 5030 | str = g_string_append(str, text); | |
| 8519 | 5031 | } else { |
| 5032 | g_string_append_unichar(str, c); | |
| 5033 | } | |
| 5034 | gtk_text_iter_forward_char(&iter); | |
| 5035 | } | |
| 5036 | ||
| 5037 | return g_string_free(str, FALSE); | |
| 8061 | 5038 | } |
| 8962 | 5039 | |
| 5040 | void gtk_imhtml_set_funcs(GtkIMHtml *imhtml, GtkIMHtmlFuncs *f) | |
| 5041 | { | |
| 5042 | g_return_if_fail(imhtml != NULL); | |
| 5043 | imhtml->funcs = f; | |
| 5044 | } | |
|
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
|
5045 | |
|
8be39f0de528
Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17288
diff
changeset
|
5046 | 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
|
5047 | { |
|
18240
0a7d2fde749b
Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
18185
diff
changeset
|
5048 | 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
|
5049 | |
|
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
|
5050 | 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
|
5051 | 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
|
5052 | 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
|
5053 | |
|
18240
0a7d2fde749b
Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
18185
diff
changeset
|
5054 | 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
|
5055 | |
|
0a7d2fde749b
Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
18185
diff
changeset
|
5056 | 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
|
5057 | 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
|
5058 | 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
|
5059 | { |
|
0a7d2fde749b
Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
18185
diff
changeset
|
5060 | 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
|
5061 | 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
|
5062 | } |
|
0a7d2fde749b
Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
18185
diff
changeset
|
5063 | 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
|
5064 | 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
|
5065 | |
|
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
|
5066 | 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
|
5067 | 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
|
5068 | 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
|
5069 | |
|
8be39f0de528
Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17288
diff
changeset
|
5070 | 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
|
5071 | 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
|
5072 | |
|
8be39f0de528
Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17288
diff
changeset
|
5073 | 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
|
5074 | 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
|
5075 | |
|
8be39f0de528
Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17288
diff
changeset
|
5076 | 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
|
5077 | 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
|
5078 | |
|
8be39f0de528
Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17288
diff
changeset
|
5079 | 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
|
5080 | { |
|
8be39f0de528
Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17288
diff
changeset
|
5081 | 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
|
5082 | |
|
8be39f0de528
Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17288
diff
changeset
|
5083 | /* 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
|
5084 | 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
|
5085 | 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
|
5086 | } |
|
8be39f0de528
Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17288
diff
changeset
|
5087 | |
|
8be39f0de528
Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17288
diff
changeset
|
5088 | 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
|
5089 | { |
|
8be39f0de528
Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17288
diff
changeset
|
5090 | 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
|
5091 | &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
|
5092 | 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
|
5093 | 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
|
5094 | 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
|
5095 | 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
|
5096 | } 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
|
5097 | 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
|
5098 | |
|
8be39f0de528
Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17288
diff
changeset
|
5099 | 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
|
5100 | |
|
8be39f0de528
Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17288
diff
changeset
|
5101 | 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
|
5102 | 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
|
5103 | { |
|
8be39f0de528
Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17288
diff
changeset
|
5104 | 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
|
5105 | &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
|
5106 | 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
|
5107 | 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
|
5108 | 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
|
5109 | 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
|
5110 | } 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
|
5111 | 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
|
5112 | |
|
8be39f0de528
Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17288
diff
changeset
|
5113 | 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
|
5114 | |
|
8be39f0de528
Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17288
diff
changeset
|
5115 | 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
|
5116 | 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
|
5117 | 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
|
5118 | 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
|
5119 | } 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
|
5120 | 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
|
5121 | 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
|
5122 | } |
|
18240
0a7d2fde749b
Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
18185
diff
changeset
|
5123 | |
|
0a7d2fde749b
Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
18185
diff
changeset
|
5124 | 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
|
5125 | 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
|
5126 | |
|
0a7d2fde749b
Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
18185
diff
changeset
|
5127 | 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
|
5128 | } |
|
8be39f0de528
Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17288
diff
changeset
|
5129 | |
|
18105
bab0b0bcb664
propagate from branch 'im.pidgin.pidgin' (head 1b4384bff09a39fca58692fb6c929d4fe1276022)
Sadrul Habib Chowdhury <sadrul@pidgin.im>
diff
changeset
|
5130 |