Wed, 20 Jun 2007 22:12:47 +0000
Round the other icons too
| 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 | |
|
699d876e3db0
Include pidgin.h to make this compile.
Richard Laager <rlaager@pidgin.im>
parents:
18108
diff
changeset
|
31 | #include "pidgin.h" |
|
18273
e61c53184c52
#include reorganizations to allow compiling with glib < 2.8 using the
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
18240
diff
changeset
|
32 | #include "internal.h" |
|
18119
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 | |
| 4417 | 57 | #ifdef ENABLE_NLS |
| 58 | # include <libintl.h> | |
| 59 | # define _(x) gettext(x) | |
| 60 | # ifdef gettext_noop | |
| 61 | # define N_(String) gettext_noop (String) | |
| 62 | # else | |
| 63 | # define N_(String) (String) | |
| 64 | # endif | |
| 65 | #else | |
| 66 | # define N_(String) (String) | |
| 67 | # define _(x) (x) | |
| 68 | #endif | |
| 69 | ||
| 4735 | 70 | #include <pango/pango-font.h> |
| 71 | ||
| 15577 | 72 | /* GTK+ < 2.4.x hack, see pidgin.h for details. */ |
|
10062
144767f0643a
[gaim-migrate @ 11037]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10016
diff
changeset
|
73 | #if (!GTK_CHECK_VERSION(2,4,0)) |
|
5105
3565a4c4de6a
[gaim-migrate @ 5468]
David J. Brigada <brigada@prism.net>
parents:
5104
diff
changeset
|
74 | #define GTK_WRAP_WORD_CHAR GTK_WRAP_WORD |
|
3565a4c4de6a
[gaim-migrate @ 5468]
David J. Brigada <brigada@prism.net>
parents:
5104
diff
changeset
|
75 | #endif |
|
3565a4c4de6a
[gaim-migrate @ 5468]
David J. Brigada <brigada@prism.net>
parents:
5104
diff
changeset
|
76 | |
| 4735 | 77 | #define TOOLTIP_TIMEOUT 500 |
| 78 | ||
| 8786 | 79 | /* GTK+ 2.0 hack */ |
| 80 | #if (!GTK_CHECK_VERSION(2,2,0)) | |
| 81 | #define gtk_widget_get_clipboard(x, y) gtk_clipboard_get(y) | |
| 82 | #endif | |
| 83 | ||
| 10100 | 84 | static GtkTextViewClass *parent_class = NULL; |
| 85 | ||
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
86 | struct scalable_data { |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
87 | GtkIMHtmlScalable *scalable; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
88 | GtkTextMark *mark; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
89 | }; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
90 | |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
91 | |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
92 | struct im_image_data { |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
93 | int id; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
94 | GtkTextMark *mark; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
95 | }; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
96 | |
| 9300 | 97 | static gboolean |
| 98 | gtk_text_view_drag_motion (GtkWidget *widget, | |
| 99 | GdkDragContext *context, | |
| 100 | gint x, | |
| 101 | gint y, | |
| 102 | guint time); | |
| 103 | ||
| 8677 | 104 | static void preinsert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml); |
| 8061 | 105 | 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
|
106 | static void delete_cb(GtkTextBuffer *buffer, GtkTextIter *iter, GtkTextIter *end, GtkIMHtml *imhtml); |
| 10169 | 107 | static void insert_ca_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextChildAnchor *arg2, gpointer user_data); |
| 108 | static void gtk_imhtml_apply_tags_on_insert(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end); | |
| 8698 | 109 | void gtk_imhtml_close_tags(GtkIMHtml *imhtml, GtkTextIter *iter); |
| 9300 | 110 | static void gtk_imhtml_link_drop_cb(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer user_data); |
| 8091 | 111 | 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 | 112 | static void mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, GtkIMHtml *imhtml); |
| 8931 | 113 | static void hijack_menu_cb(GtkIMHtml *imhtml, GtkMenu *menu, gpointer data); |
| 114 | static void paste_received_cb (GtkClipboard *clipboard, GtkSelectionData *selection_data, gpointer data); | |
| 115 | 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
|
116 | 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
|
117 | static void imhtml_toggle_bold(GtkIMHtml *imhtml); |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
118 | static void imhtml_toggle_italic(GtkIMHtml *imhtml); |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
119 | static void imhtml_toggle_strike(GtkIMHtml *imhtml); |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
120 | static void imhtml_toggle_underline(GtkIMHtml *imhtml); |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
121 | static void imhtml_font_grow(GtkIMHtml *imhtml); |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
122 | static void imhtml_font_shrink(GtkIMHtml *imhtml); |
|
12672
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
123 | static void imhtml_clear_formatting(GtkIMHtml *imhtml); |
| 8061 | 124 | |
|
10899
87d9aec5b72d
[gaim-migrate @ 12619]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10871
diff
changeset
|
125 | /* POINT_SIZE converts from AIM font sizes to a point size scale factor. */ |
| 3922 | 126 | #define MAX_FONT_SIZE 7 |
|
10900
cc19dfd83910
[gaim-migrate @ 12621]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10899
diff
changeset
|
127 | #define POINT_SIZE(x) (_point_sizes [MIN ((x > 0 ? x : 1), MAX_FONT_SIZE) - 1]) |
| 14741 | 128 | 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
|
129 | |
|
10184
543c9a84ce16
[gaim-migrate @ 11299]
Mark Doliner <markdoliner@pidgin.im>
parents:
10169
diff
changeset
|
130 | enum { |
| 8677 | 131 | TARGET_HTML, |
| 8061 | 132 | TARGET_UTF8_STRING, |
| 133 | TARGET_COMPOUND_TEXT, | |
| 134 | TARGET_STRING, | |
| 135 | TARGET_TEXT | |
| 136 | }; | |
| 137 | ||
| 8091 | 138 | enum { |
| 8420 | 139 | URL_CLICKED, |
| 140 | BUTTONS_UPDATE, | |
| 141 | TOGGLE_FORMAT, | |
| 8427 | 142 | CLEAR_FORMAT, |
| 8506 | 143 | UPDATE_FORMAT, |
| 10108 | 144 | 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
|
145 | 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
|
146 | REDO, |
| 8420 | 147 | LAST_SIGNAL |
| 148 | }; | |
| 149 | static guint signals [LAST_SIGNAL] = { 0 }; | |
| 150 | ||
|
17546
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
151 | 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
|
152 | 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
|
153 | 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
|
154 | |
|
10871
c0282a4f2250
[gaim-migrate @ 12558]
Mark Doliner <markdoliner@pidgin.im>
parents:
10865
diff
changeset
|
155 | static GtkTargetEntry selection_targets[] = { |
|
15111
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
156 | #ifndef _WIN32 |
| 8566 | 157 | { "text/html", 0, TARGET_HTML }, |
|
15111
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
158 | #else |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
159 | { "HTML Format", 0, TARGET_HTML }, |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
160 | #endif |
| 8061 | 161 | { "UTF8_STRING", 0, TARGET_UTF8_STRING }, |
| 162 | { "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT }, | |
| 163 | { "STRING", 0, TARGET_STRING }, | |
| 164 | { "TEXT", 0, TARGET_TEXT}}; | |
| 165 | ||
|
10871
c0282a4f2250
[gaim-migrate @ 12558]
Mark Doliner <markdoliner@pidgin.im>
parents:
10865
diff
changeset
|
166 | static GtkTargetEntry link_drag_drop_targets[] = { |
|
10145
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
167 | GTK_IMHTML_DND_TARGETS |
|
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
168 | }; |
| 8091 | 169 | |
| 8692 | 170 | #ifdef _WIN32 |
| 171 | static gchar * | |
| 172 | clipboard_win32_to_html(char *clipboard) { | |
| 9465 | 173 | const char *header; |
| 8693 | 174 | const char *begin, *end; |
|
10016
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
175 | gint start = 0; |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
176 | gint finish = 0; |
| 8692 | 177 | gchar *html; |
|
10016
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
178 | gchar **split; |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
179 | int clipboard_length = 0; |
| 9465 | 180 | |
| 181 | #if 0 /* Debugging for Windows clipboard */ | |
| 9467 | 182 | FILE *fd; |
| 183 | ||
| 15884 | 184 | purple_debug_info("imhtml clipboard", "from clipboard: %s\n", clipboard); |
| 185 | ||
| 186 | fd = g_fopen("e:\\purplecb.txt", "wb"); | |
| 9465 | 187 | fprintf(fd, "%s", clipboard); |
| 188 | fclose(fd); | |
| 189 | #endif | |
| 190 | ||
|
10016
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
191 | clipboard_length = strlen(clipboard); |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
192 | |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
193 | if (!(header = strstr(clipboard, "StartFragment:")) || (header - clipboard) >= clipboard_length) |
| 9465 | 194 | return NULL; |
| 195 | sscanf(header, "StartFragment:%d", &start); | |
| 196 | ||
|
10016
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
197 | if (!(header = strstr(clipboard, "EndFragment:")) || (header - clipboard) >= clipboard_length) |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
198 | return NULL; |
| 9465 | 199 | sscanf(header, "EndFragment:%d", &finish); |
| 200 | ||
|
10016
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
201 | if (finish > clipboard_length) |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
202 | finish = clipboard_length; |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
203 | |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
204 | if (start > finish) |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
205 | start = finish; |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
206 | |
| 9465 | 207 | begin = clipboard + start; |
| 208 | ||
|
10016
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
209 | end = clipboard + finish; |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
210 | |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
211 | html = g_strndup(begin, end - begin); |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
212 | |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
213 | /* 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
|
214 | split = g_strsplit(html, "\r\n", 0); |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
215 | g_free(html); |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
216 | html = g_strjoinv("\n", split); |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
217 | g_strfreev(split); |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
218 | |
|
18418b9fa749
[gaim-migrate @ 10935]
Daniel Atallah <datallah@pidgin.im>
parents:
10013
diff
changeset
|
219 | html = g_strstrip(html); |
| 9465 | 220 | |
| 221 | #if 0 /* Debugging for Windows clipboard */ | |
| 15884 | 222 | purple_debug_info("imhtml clipboard", "HTML fragment: '%s'\n", html); |
| 9465 | 223 | #endif |
| 224 | ||
| 8707 | 225 | return html; |
| 8692 | 226 | } |
| 227 | ||
| 228 | static gchar * | |
| 229 | clipboard_html_to_win32(char *html) { | |
| 8693 | 230 | int length; |
|
11240
cd4ca16ff57c
[gaim-migrate @ 13399]
Richard Laager <rlaager@pidgin.im>
parents:
11234
diff
changeset
|
231 | GString *clipboard; |
|
cd4ca16ff57c
[gaim-migrate @ 13399]
Richard Laager <rlaager@pidgin.im>
parents:
11234
diff
changeset
|
232 | gchar *tmp; |
| 8692 | 233 | |
| 8693 | 234 | if (html == NULL) |
| 235 | return NULL; | |
| 8692 | 236 | |
| 237 | length = strlen(html); | |
| 9465 | 238 | clipboard = g_string_new ("Version:1.0\r\n"); |
| 8692 | 239 | g_string_append(clipboard, "StartHTML:0000000105\r\n"); |
|
11240
cd4ca16ff57c
[gaim-migrate @ 13399]
Richard Laager <rlaager@pidgin.im>
parents:
11234
diff
changeset
|
240 | tmp = g_strdup_printf("EndHTML:%010d\r\n", 147 + length); |
|
cd4ca16ff57c
[gaim-migrate @ 13399]
Richard Laager <rlaager@pidgin.im>
parents:
11234
diff
changeset
|
241 | g_string_append(clipboard, tmp); |
|
cd4ca16ff57c
[gaim-migrate @ 13399]
Richard Laager <rlaager@pidgin.im>
parents:
11234
diff
changeset
|
242 | g_free(tmp); |
| 9465 | 243 | g_string_append(clipboard, "StartFragment:0000000127\r\n"); |
|
11240
cd4ca16ff57c
[gaim-migrate @ 13399]
Richard Laager <rlaager@pidgin.im>
parents:
11234
diff
changeset
|
244 | tmp = g_strdup_printf("EndFragment:%010d\r\n", 127 + length); |
|
cd4ca16ff57c
[gaim-migrate @ 13399]
Richard Laager <rlaager@pidgin.im>
parents:
11234
diff
changeset
|
245 | g_string_append(clipboard, tmp); |
|
cd4ca16ff57c
[gaim-migrate @ 13399]
Richard Laager <rlaager@pidgin.im>
parents:
11234
diff
changeset
|
246 | g_free(tmp); |
| 9465 | 247 | g_string_append(clipboard, "<!--StartFragment-->\r\n"); |
| 8692 | 248 | g_string_append(clipboard, html); |
| 9465 | 249 | g_string_append(clipboard, "\r\n<!--EndFragment-->"); |
|
14101
89a79c2a971e
[gaim-migrate @ 16643]
Mark Doliner <markdoliner@pidgin.im>
parents:
14097
diff
changeset
|
250 | |
|
89a79c2a971e
[gaim-migrate @ 16643]
Mark Doliner <markdoliner@pidgin.im>
parents:
14097
diff
changeset
|
251 | return g_string_free(clipboard, FALSE); |
| 8692 | 252 | } |
|
10901
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
253 | |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
254 | static gboolean clipboard_paste_html_win32(GtkIMHtml *imhtml) { |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
255 | gboolean pasted = FALSE; |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
256 | |
|
15111
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
257 | /* Win32 clipboard format value, and functions to convert back and |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
258 | * forth between HTML and the clipboard format. |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
259 | */ |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
260 | static UINT win_html_fmt = 0; |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
261 | |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
262 | /* Register HTML Format as desired clipboard format */ |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
263 | if (!win_html_fmt) |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
264 | win_html_fmt = RegisterClipboardFormat("HTML Format"); |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
265 | |
|
10901
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
266 | if (gtk_text_view_get_editable(GTK_TEXT_VIEW(imhtml)) |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
267 | && IsClipboardFormatAvailable(win_html_fmt)) { |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
268 | gboolean error_reading_clipboard = FALSE; |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
269 | HWND hwnd = GDK_WINDOW_HWND(GTK_WIDGET(imhtml)->window); |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
270 | |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
271 | if (OpenClipboard(hwnd)) { |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
272 | HGLOBAL hdata = GetClipboardData(win_html_fmt); |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
273 | if (hdata == NULL) { |
|
15111
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
274 | if (GetLastError() != ERROR_SUCCESS) |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
275 | error_reading_clipboard = TRUE; |
|
10901
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
276 | } else { |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
277 | char *buffer = GlobalLock(hdata); |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
278 | if (buffer == NULL) { |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
279 | error_reading_clipboard = TRUE; |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
280 | } else { |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
281 | char *text = clipboard_win32_to_html( |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
282 | buffer); |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
283 | imhtml_paste_insert(imhtml, text, |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
284 | FALSE); |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
285 | g_free(text); |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
286 | pasted = TRUE; |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
287 | } |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
288 | GlobalUnlock(hdata); |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
289 | } |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
290 | |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
291 | CloseClipboard(); |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
292 | } else { |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
293 | error_reading_clipboard = TRUE; |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
294 | } |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
295 | |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
296 | if (error_reading_clipboard) { |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
297 | gchar *err_msg = g_win32_error_message(GetLastError()); |
| 15884 | 298 | purple_debug_info("html clipboard", |
|
10901
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
299 | "Unable to read clipboard data: %s\n", |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
300 | err_msg ? err_msg : "Unknown Error"); |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
301 | g_free(err_msg); |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
302 | } |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
303 | } |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
304 | |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
305 | return pasted; |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
306 | } |
| 8692 | 307 | #endif |
| 308 | ||
| 4032 | 309 | static GtkSmileyTree* |
| 310 | gtk_smiley_tree_new () | |
| 311 | { | |
| 312 | return g_new0 (GtkSmileyTree, 1); | |
| 313 | } | |
| 314 | ||
| 315 | static void | |
| 316 | gtk_smiley_tree_insert (GtkSmileyTree *tree, | |
| 4263 | 317 | GtkIMHtmlSmiley *smiley) |
| 4032 | 318 | { |
| 319 | GtkSmileyTree *t = tree; | |
| 4263 | 320 | const gchar *x = smiley->smile; |
| 4032 | 321 | |
|
12229
ad8d3ae8fc1b
[gaim-migrate @ 14531]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12072
diff
changeset
|
322 | if (!(*x)) |
| 4032 | 323 | return; |
| 324 | ||
|
12229
ad8d3ae8fc1b
[gaim-migrate @ 14531]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12072
diff
changeset
|
325 | do { |
| 4032 | 326 | gchar *pos; |
| 327 | gint index; | |
| 328 | ||
| 329 | if (!t->values) | |
| 330 | t->values = g_string_new (""); | |
| 331 | ||
| 332 | pos = strchr (t->values->str, *x); | |
| 333 | if (!pos) { | |
| 334 | t->values = g_string_append_c (t->values, *x); | |
| 335 | index = t->values->len - 1; | |
| 336 | t->children = g_realloc (t->children, t->values->len * sizeof (GtkSmileyTree *)); | |
| 337 | t->children [index] = g_new0 (GtkSmileyTree, 1); | |
| 338 | } else | |
| 7386 | 339 | index = GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str); |
| 8061 | 340 | |
| 4032 | 341 | t = t->children [index]; |
| 8061 | 342 | |
| 4032 | 343 | x++; |
|
12229
ad8d3ae8fc1b
[gaim-migrate @ 14531]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12072
diff
changeset
|
344 | } while (*x); |
| 8061 | 345 | |
| 4263 | 346 | t->image = smiley; |
| 4032 | 347 | } |
| 4041 | 348 | |
| 4263 | 349 | |
|
11677
89c2ab8d2ebf
[gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents:
11586
diff
changeset
|
350 | static void |
|
89c2ab8d2ebf
[gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents:
11586
diff
changeset
|
351 | gtk_smiley_tree_destroy (GtkSmileyTree *tree) |
| 4032 | 352 | { |
|
11701
8cf812de5e92
[gaim-migrate @ 13992]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
11677
diff
changeset
|
353 | GSList *list = g_slist_prepend (NULL, tree); |
| 4032 | 354 | |
| 355 | while (list) { | |
| 356 | GtkSmileyTree *t = list->data; | |
|
12229
ad8d3ae8fc1b
[gaim-migrate @ 14531]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12072
diff
changeset
|
357 | gsize i; |
| 4032 | 358 | list = g_slist_remove(list, t); |
| 7384 | 359 | if (t && t->values) { |
| 4032 | 360 | for (i = 0; i < t->values->len; i++) |
|
11701
8cf812de5e92
[gaim-migrate @ 13992]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
11677
diff
changeset
|
361 | list = g_slist_prepend (list, t->children [i]); |
| 4032 | 362 | g_string_free (t->values, TRUE); |
| 363 | g_free (t->children); | |
| 364 | } | |
| 365 | g_free (t); | |
| 366 | } | |
| 367 | } | |
| 368 | ||
|
11840
c9ec5a42d420
[gaim-migrate @ 14131]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11820
diff
changeset
|
369 | static void gtk_size_allocate_cb(GtkIMHtml *widget, GtkAllocation *alloc, gpointer user_data) |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
370 | { |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
371 | GdkRectangle rect; |
| 8726 | 372 | int xminus; |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
373 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
374 | gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(widget), &rect); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
375 | if(widget->old_rect.width != rect.width || widget->old_rect.height != rect.height){ |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
376 | GList *iter = GTK_IMHTML(widget)->scalables; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
377 | |
| 8726 | 378 | xminus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(widget)) + |
| 379 | gtk_text_view_get_right_margin(GTK_TEXT_VIEW(widget)); | |
| 380 | ||
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
381 | while(iter){ |
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
382 | struct scalable_data *sd = iter->data; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
383 | GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(sd->scalable); |
| 8726 | 384 | scale->scale(scale, rect.width - xminus, rect.height); |
|
5967
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 | iter = iter->next; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
387 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
388 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
389 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
390 | widget->old_rect = rect; |
|
11840
c9ec5a42d420
[gaim-migrate @ 14131]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11820
diff
changeset
|
391 | return; |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
392 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
393 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
394 | static gint |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
395 | gtk_imhtml_tip_paint (GtkIMHtml *imhtml) |
|
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 | PangoLayout *layout; |
|
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 | g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
400 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
401 | layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
402 | |
| 8061 | 403 | 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
|
404 | GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, imhtml->tip_window, |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
405 | "tooltip", 0, 0, -1, -1); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
406 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
407 | 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
|
408 | FALSE, NULL, imhtml->tip_window, NULL, 4, 4, layout); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
409 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
410 | g_object_unref(layout); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
411 | return FALSE; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
412 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
413 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
414 | static gint |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
415 | gtk_imhtml_tip (gpointer data) |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
416 | { |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
417 | GtkIMHtml *imhtml = data; |
| 8526 | 418 | PangoFontMetrics *font_metrics; |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
419 | PangoLayout *layout; |
| 8526 | 420 | PangoFont *font; |
|
5967
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 | gint gap, x, y, h, w, scr_w, baseline_skip; |
|
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 | g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
425 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
426 | if (!imhtml->tip || !GTK_WIDGET_DRAWABLE (GTK_WIDGET(imhtml))) { |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
427 | imhtml->tip_timer = 0; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
428 | return FALSE; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
429 | } |
| 8061 | 430 | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
431 | if (imhtml->tip_window){ |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
432 | gtk_widget_destroy (imhtml->tip_window); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
433 | imhtml->tip_window = NULL; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
434 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
435 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
436 | imhtml->tip_timer = 0; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
437 | imhtml->tip_window = gtk_window_new (GTK_WINDOW_POPUP); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
438 | gtk_widget_set_app_paintable (imhtml->tip_window, TRUE); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
439 | gtk_window_set_resizable (GTK_WINDOW (imhtml->tip_window), FALSE); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
440 | gtk_widget_set_name (imhtml->tip_window, "gtk-tooltips"); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
441 | g_signal_connect_swapped (G_OBJECT (imhtml->tip_window), "expose_event", |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
442 | G_CALLBACK (gtk_imhtml_tip_paint), imhtml); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
443 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
444 | gtk_widget_ensure_style (imhtml->tip_window); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
445 | layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip); |
| 8526 | 446 | font = pango_context_load_font(pango_layout_get_context(layout), |
| 447 | imhtml->tip_window->style->font_desc); | |
| 448 | ||
| 449 | if (font == NULL) { | |
| 450 | char *tmp = pango_font_description_to_string( | |
| 451 | imhtml->tip_window->style->font_desc); | |
| 452 | ||
| 15884 | 453 | purple_debug(PURPLE_DEBUG_ERROR, "gtk_imhtml_tip", |
| 8526 | 454 | "pango_context_load_font() couldn't load font: '%s'\n", |
| 455 | tmp); | |
| 456 | g_free(tmp); | |
| 457 | ||
| 458 | return FALSE; | |
| 459 | } | |
| 460 | ||
| 461 | font_metrics = pango_font_get_metrics(font, NULL); | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
462 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
463 | pango_layout_get_pixel_size(layout, &scr_w, NULL); |
| 8526 | 464 | gap = PANGO_PIXELS((pango_font_metrics_get_ascent(font_metrics) + |
| 465 | pango_font_metrics_get_descent(font_metrics))/ 4); | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
466 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
467 | if (gap < 2) |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
468 | gap = 2; |
| 8526 | 469 | baseline_skip = PANGO_PIXELS(pango_font_metrics_get_ascent(font_metrics) + |
| 470 | pango_font_metrics_get_descent(font_metrics)); | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
471 | w = 8 + scr_w; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
472 | h = 8 + baseline_skip; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
473 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
474 | gdk_window_get_pointer (NULL, &x, &y, NULL); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
475 | if (GTK_WIDGET_NO_WINDOW (GTK_WIDGET(imhtml))) |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
476 | y += GTK_WIDGET(imhtml)->allocation.y; |
|
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 | scr_w = gdk_screen_width(); |
|
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 | x -= ((w >> 1) + 4); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
481 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
482 | if ((x + w) > scr_w) |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
483 | x -= (x + w) - scr_w; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
484 | else if (x < 0) |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
485 | x = 0; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
486 | |
| 8526 | 487 | y = y + PANGO_PIXELS(pango_font_metrics_get_ascent(font_metrics) + |
| 488 | pango_font_metrics_get_descent(font_metrics)); | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
489 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
490 | 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
|
491 | gtk_window_move (GTK_WINDOW(imhtml->tip_window), x, y); |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
492 | gtk_widget_show (imhtml->tip_window); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
493 | |
| 8526 | 494 | pango_font_metrics_unref(font_metrics); |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
495 | g_object_unref(layout); |
|
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 | return FALSE; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
498 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
499 | |
|
11844
57ad7c52cc9c
[gaim-migrate @ 14135]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11840
diff
changeset
|
500 | static gboolean |
|
57ad7c52cc9c
[gaim-migrate @ 14135]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11840
diff
changeset
|
501 | gtk_motion_event_notify(GtkWidget *imhtml, GdkEventMotion *event, gpointer data) |
| 8061 | 502 | { |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
503 | GtkTextIter iter; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
504 | GdkWindow *win = event->window; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
505 | int x, y; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
506 | char *tip = NULL; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
507 | GSList *tags = NULL, *templist = NULL; |
| 10799 | 508 | GdkColor *norm, *pre; |
| 509 | GtkTextTag *tag = NULL, *oldprelit_tag; | |
| 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 | |
| 10799 | 567 | if (tip){ |
| 8061 | 568 | if (!GTK_IMHTML(imhtml)->editable) |
| 569 | gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->hand_cursor); | |
| 570 | GTK_IMHTML(imhtml)->tip_timer = g_timeout_add (TOOLTIP_TIMEOUT, | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
571 | gtk_imhtml_tip, imhtml); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
572 | } |
| 8061 | 573 | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
574 | GTK_IMHTML(imhtml)->tip = tip; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
575 | g_slist_free(tags); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
576 | return FALSE; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
577 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
578 | |
|
11677
89c2ab8d2ebf
[gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents:
11586
diff
changeset
|
579 | static gboolean |
|
89c2ab8d2ebf
[gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents:
11586
diff
changeset
|
580 | gtk_enter_event_notify(GtkWidget *imhtml, GdkEventCrossing *event, gpointer data) |
|
10946
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
581 | { |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
582 | if (GTK_IMHTML(imhtml)->editable) |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
583 | gdk_window_set_cursor( |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
584 | gtk_text_view_get_window(GTK_TEXT_VIEW(imhtml), |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
585 | GTK_TEXT_WINDOW_TEXT), |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
586 | GTK_IMHTML(imhtml)->text_cursor); |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
587 | else |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
588 | gdk_window_set_cursor( |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
589 | gtk_text_view_get_window(GTK_TEXT_VIEW(imhtml), |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
590 | GTK_TEXT_WINDOW_TEXT), |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
591 | GTK_IMHTML(imhtml)->arrow_cursor); |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
592 | |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
593 | /* propagate the event normally */ |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
594 | return FALSE; |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
595 | } |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
596 | |
|
11677
89c2ab8d2ebf
[gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents:
11586
diff
changeset
|
597 | static gboolean |
|
89c2ab8d2ebf
[gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents:
11586
diff
changeset
|
598 | gtk_leave_event_notify(GtkWidget *imhtml, GdkEventCrossing *event, gpointer data) |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
599 | { |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
600 | /* when leaving the widget, clear any current & pending tooltips and restore the cursor */ |
| 10799 | 601 | if (GTK_IMHTML(imhtml)->prelit_tag) { |
| 602 | GdkColor *norm; | |
| 603 | gtk_widget_style_get(GTK_WIDGET(imhtml), "hyperlink-color", &norm, NULL); | |
| 604 | if (norm) | |
| 605 | g_object_set(G_OBJECT(GTK_IMHTML(imhtml)->prelit_tag), "foreground-gdk", norm, NULL); | |
| 606 | else | |
| 607 | g_object_set(G_OBJECT(GTK_IMHTML(imhtml)->prelit_tag), "foreground", "blue", NULL); | |
| 608 | GTK_IMHTML(imhtml)->prelit_tag = NULL; | |
| 609 | } | |
| 610 | ||
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
611 | if (GTK_IMHTML(imhtml)->tip_window) { |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
612 | gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
613 | GTK_IMHTML(imhtml)->tip_window = NULL; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
614 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
615 | if (GTK_IMHTML(imhtml)->tip_timer) { |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
616 | g_source_remove(GTK_IMHTML(imhtml)->tip_timer); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
617 | GTK_IMHTML(imhtml)->tip_timer = 0; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
618 | } |
|
10946
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
619 | gdk_window_set_cursor( |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
620 | gtk_text_view_get_window(GTK_TEXT_VIEW(imhtml), |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
621 | GTK_TEXT_WINDOW_TEXT), NULL); |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
622 | |
|
8568
66907b37ce85
[gaim-migrate @ 9316]
Mark Doliner <markdoliner@pidgin.im>
parents:
8566
diff
changeset
|
623 | /* propagate the event normally */ |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
624 | return FALSE; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
625 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
626 | |
|
10844
fb5b88957742
[gaim-migrate @ 12516]
Richard Laager <rlaager@pidgin.im>
parents:
10834
diff
changeset
|
627 | #if (!GTK_CHECK_VERSION(2,2,0)) |
| 6066 | 628 | /* |
| 629 | * XXX - This should be removed eventually. | |
| 630 | * | |
| 8061 | 631 | * This function exists to work around a gross bug in GtkTextView. |
| 632 | * Basically, we short circuit ctrl+a and ctrl+end because they make | |
| 6066 | 633 | * el program go boom. |
| 634 | * | |
| 8061 | 635 | * It's supposed to be fixed in gtk2.2. You can view the bug report at |
| 6066 | 636 | * http://bugzilla.gnome.org/show_bug.cgi?id=107939 |
| 637 | */ | |
|
10849
476d68d7a435
[gaim-migrate @ 12521]
Richard Laager <rlaager@pidgin.im>
parents:
10844
diff
changeset
|
638 | static gboolean |
|
476d68d7a435
[gaim-migrate @ 12521]
Richard Laager <rlaager@pidgin.im>
parents:
10844
diff
changeset
|
639 | gtk_key_pressed_cb(GtkIMHtml *imhtml, GdkEventKey *event, gpointer data) |
| 8677 | 640 | { |
|
10844
fb5b88957742
[gaim-migrate @ 12516]
Richard Laager <rlaager@pidgin.im>
parents:
10834
diff
changeset
|
641 | if (event->state & GDK_CONTROL_MASK) { |
| 6066 | 642 | switch (event->keyval) { |
|
10844
fb5b88957742
[gaim-migrate @ 12516]
Richard Laager <rlaager@pidgin.im>
parents:
10834
diff
changeset
|
643 | case 'a': |
|
fb5b88957742
[gaim-migrate @ 12516]
Richard Laager <rlaager@pidgin.im>
parents:
10834
diff
changeset
|
644 | case GDK_Home: |
|
fb5b88957742
[gaim-migrate @ 12516]
Richard Laager <rlaager@pidgin.im>
parents:
10834
diff
changeset
|
645 | case GDK_End: |
|
fb5b88957742
[gaim-migrate @ 12516]
Richard Laager <rlaager@pidgin.im>
parents:
10834
diff
changeset
|
646 | return TRUE; |
| 6066 | 647 | } |
|
10844
fb5b88957742
[gaim-migrate @ 12516]
Richard Laager <rlaager@pidgin.im>
parents:
10834
diff
changeset
|
648 | } |
| 6066 | 649 | return FALSE; |
| 650 | } | |
|
10844
fb5b88957742
[gaim-migrate @ 12516]
Richard Laager <rlaager@pidgin.im>
parents:
10834
diff
changeset
|
651 | #endif /* !(GTK+ >= 2.2.0) */ |
| 10692 | 652 | |
| 653 | static gint | |
| 654 | gtk_imhtml_expose_event (GtkWidget *widget, | |
| 655 | GdkEventExpose *event) | |
| 656 | { | |
| 10776 | 657 | GtkTextIter start, end, cur; |
| 658 | int buf_x, buf_y; | |
| 659 | GdkRectangle visible_rect; | |
| 10777 | 660 | GdkGC *gc = gdk_gc_new(GDK_DRAWABLE(event->window)); |
| 661 | GdkColor gcolor; | |
|
10844
fb5b88957742
[gaim-migrate @ 12516]
Richard Laager <rlaager@pidgin.im>
parents:
10834
diff
changeset
|
662 | |
| 10776 | 663 | gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(widget), &visible_rect); |
| 664 | gtk_text_view_buffer_to_window_coords(GTK_TEXT_VIEW(widget), | |
| 665 | GTK_TEXT_WINDOW_TEXT, | |
| 666 | visible_rect.x, | |
| 667 | visible_rect.y, | |
| 668 | &visible_rect.x, | |
| 669 | &visible_rect.y); | |
| 670 | ||
| 671 | gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(widget), GTK_TEXT_WINDOW_TEXT, | |
| 672 | event->area.x, event->area.y, &buf_x, &buf_y); | |
| 673 | ||
| 10777 | 674 | if (GTK_IMHTML(widget)->editable || GTK_IMHTML(widget)->wbfo) { |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
675 | |
| 10777 | 676 | if (GTK_IMHTML(widget)->edit.background) { |
| 677 | gdk_color_parse(GTK_IMHTML(widget)->edit.background, &gcolor); | |
| 678 | gdk_gc_set_rgb_fg_color(gc, &gcolor); | |
| 679 | } else { | |
| 680 | gdk_gc_set_rgb_fg_color(gc, &(widget->style->base[GTK_WIDGET_STATE(widget)])); | |
| 681 | } | |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
682 | |
| 10777 | 683 | gdk_draw_rectangle(event->window, |
| 684 | gc, | |
| 685 | TRUE, | |
| 686 | visible_rect.x, visible_rect.y, visible_rect.width, visible_rect.height); | |
| 687 | gdk_gc_unref(gc); | |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
688 | |
| 10777 | 689 | if (GTK_WIDGET_CLASS (parent_class)->expose_event) |
| 690 | return (* GTK_WIDGET_CLASS (parent_class)->expose_event) | |
| 691 | (widget, event); | |
| 692 | return FALSE; | |
| 693 | ||
| 694 | } | |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
695 | |
| 10776 | 696 | gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(widget), &start, buf_x, buf_y); |
| 697 | gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(widget), &end, | |
| 698 | buf_x + event->area.width, buf_y + event->area.height); | |
| 699 | ||
| 700 | ||
| 701 | ||
| 702 | cur = start; | |
| 703 | ||
| 704 | while (gtk_text_iter_in_range(&cur, &start, &end)) { | |
| 10795 | 705 | GSList *tags = gtk_text_iter_get_tags(&cur); |
| 706 | GSList *l; | |
| 10776 | 707 | |
| 708 | for (l = tags; l; l = l->next) { | |
| 709 | GtkTextTag *tag = l->data; | |
| 710 | GdkRectangle rect; | |
| 711 | GdkRectangle tag_area; | |
| 712 | const char *color; | |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
713 | |
| 10776 | 714 | if (strncmp(tag->name, "BACKGROUND ", 11)) |
| 715 | continue; | |
| 716 | ||
| 717 | if (gtk_text_iter_ends_tag(&cur, tag)) | |
| 718 | continue; | |
| 719 | ||
| 720 | gtk_text_view_get_iter_location(GTK_TEXT_VIEW(widget), &cur, &tag_area); | |
| 721 | gtk_text_view_buffer_to_window_coords(GTK_TEXT_VIEW(widget), | |
| 722 | GTK_TEXT_WINDOW_TEXT, | |
| 723 | tag_area.x, | |
| 724 | tag_area.y, | |
| 725 | &tag_area.x, | |
| 726 | &tag_area.y); | |
| 727 | rect.x = visible_rect.x; | |
| 728 | rect.y = tag_area.y; | |
|
11768
b45e26d7a4c9
[gaim-migrate @ 14059]
Gary Kramlich <grim@reaperworld.com>
parents:
11760
diff
changeset
|
729 | rect.width = visible_rect.width; |
| 10776 | 730 | |
| 10795 | 731 | do |
| 10776 | 732 | gtk_text_iter_forward_to_tag_toggle(&cur, tag); |
| 10795 | 733 | while (!gtk_text_iter_is_end(&cur) && gtk_text_iter_begins_tag(&cur, tag)); |
| 734 | ||
| 10776 | 735 | gtk_text_view_get_iter_location(GTK_TEXT_VIEW(widget), &cur, &tag_area); |
| 736 | gtk_text_view_buffer_to_window_coords(GTK_TEXT_VIEW(widget), | |
| 737 | GTK_TEXT_WINDOW_TEXT, | |
| 738 | tag_area.x, | |
| 739 | tag_area.y, | |
| 740 | &tag_area.x, | |
| 741 | &tag_area.y); | |
| 742 | ||
| 11760 | 743 | |
| 744 | rect.height = tag_area.y + tag_area.height - rect.y | |
| 745 | + 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
|
746 | |
| 10776 | 747 | color = tag->name + 11; |
| 748 | ||
| 10857 | 749 | if (!gdk_color_parse(color, &gcolor)) { |
| 10858 | 750 | gchar tmp[8]; |
| 751 | tmp[0] = '#'; | |
| 752 | strncpy(&tmp[1], color, 7); | |
| 753 | tmp[7] = '\0'; | |
| 10857 | 754 | if (!gdk_color_parse(tmp, &gcolor)) |
| 755 | gdk_color_parse("white", &gcolor); | |
| 756 | } | |
| 10776 | 757 | gdk_gc_set_rgb_fg_color(gc, &gcolor); |
| 758 | ||
| 759 | gdk_draw_rectangle(event->window, | |
| 760 | gc, | |
| 761 | TRUE, | |
| 762 | rect.x, rect.y, rect.width, rect.height); | |
| 10795 | 763 | gtk_text_iter_backward_char(&cur); /* go back one, in case the end is the begining is the end |
| 764 | * note that above, we always moved cur ahead by at least | |
| 765 | * one character */ | |
| 10776 | 766 | break; |
| 767 | } | |
| 768 | ||
| 769 | g_slist_free(tags); | |
| 10795 | 770 | |
| 771 | /* loop until another tag begins, or no tag begins */ | |
| 772 | while (gtk_text_iter_forward_to_tag_toggle(&cur, NULL) && | |
| 773 | !gtk_text_iter_is_end(&cur) && | |
| 774 | !gtk_text_iter_begins_tag(&cur, NULL)); | |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
775 | } |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
776 | |
| 10777 | 777 | gdk_gc_unref(gc); |
| 778 | ||
| 10692 | 779 | if (GTK_WIDGET_CLASS (parent_class)->expose_event) |
| 780 | return (* GTK_WIDGET_CLASS (parent_class)->expose_event) | |
| 781 | (widget, event); | |
| 10776 | 782 | |
| 10692 | 783 | return FALSE; |
| 784 | } | |
| 785 | ||
| 786 | ||
| 8931 | 787 | static void paste_unformatted_cb(GtkMenuItem *menu, GtkIMHtml *imhtml) |
| 788 | { | |
| 789 | GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD); | |
| 790 | ||
| 791 | gtk_clipboard_request_text(clipboard, paste_plaintext_received_cb, imhtml); | |
| 792 | ||
| 793 | } | |
| 794 | ||
| 13336 | 795 | static void clear_formatting_cb(GtkMenuItem *menu, GtkIMHtml *imhtml) |
| 796 | { | |
| 797 | gtk_imhtml_clear_formatting(imhtml); | |
| 798 | } | |
| 10692 | 799 | |
| 8931 | 800 | static void hijack_menu_cb(GtkIMHtml *imhtml, GtkMenu *menu, gpointer data) |
| 801 | { | |
| 802 | GtkWidget *menuitem; | |
| 803 | ||
|
12635
5b2fbc3da55b
[gaim-migrate @ 14971]
Richard Laager <rlaager@pidgin.im>
parents:
12605
diff
changeset
|
804 | menuitem = gtk_menu_item_new_with_mnemonic(_("Paste as Plain _Text")); |
| 8931 | 805 | gtk_widget_show(menuitem); |
|
14970
fd8984ce4fda
[gaim-migrate @ 17680]
Mark Doliner <markdoliner@pidgin.im>
parents:
14863
diff
changeset
|
806 | /* |
|
fd8984ce4fda
[gaim-migrate @ 17680]
Mark Doliner <markdoliner@pidgin.im>
parents:
14863
diff
changeset
|
807 | * TODO: gtk_clipboard_wait_is_text_available() iterates the glib |
|
fd8984ce4fda
[gaim-migrate @ 17680]
Mark Doliner <markdoliner@pidgin.im>
parents:
14863
diff
changeset
|
808 | * mainloop, which tends to be a source of bugs. It would |
|
fd8984ce4fda
[gaim-migrate @ 17680]
Mark Doliner <markdoliner@pidgin.im>
parents:
14863
diff
changeset
|
809 | * be good to audit this or change it to not wait. |
|
fd8984ce4fda
[gaim-migrate @ 17680]
Mark Doliner <markdoliner@pidgin.im>
parents:
14863
diff
changeset
|
810 | */ |
| 8931 | 811 | gtk_widget_set_sensitive(menuitem, |
|
12836
837fe5d43dac
[gaim-migrate @ 15184]
Richard Laager <rlaager@pidgin.im>
parents:
12833
diff
changeset
|
812 | (imhtml->editable && |
|
837fe5d43dac
[gaim-migrate @ 15184]
Richard Laager <rlaager@pidgin.im>
parents:
12833
diff
changeset
|
813 | gtk_clipboard_wait_is_text_available( |
|
837fe5d43dac
[gaim-migrate @ 15184]
Richard Laager <rlaager@pidgin.im>
parents:
12833
diff
changeset
|
814 | gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD)))); |
| 8931 | 815 | /* put it after "Paste" */ |
| 816 | gtk_menu_shell_insert(GTK_MENU_SHELL(menu), menuitem, 3); | |
| 817 | ||
| 818 | g_signal_connect(G_OBJECT(menuitem), "activate", | |
| 819 | G_CALLBACK(paste_unformatted_cb), imhtml); | |
| 13336 | 820 | |
|
13539
8036a635a316
[gaim-migrate @ 15915]
Richard Laager <rlaager@pidgin.im>
parents:
13340
diff
changeset
|
821 | menuitem = gtk_menu_item_new_with_mnemonic(_("_Reset formatting")); |
| 13336 | 822 | gtk_widget_show(menuitem); |
|
13340
e18166659513
[gaim-migrate @ 15709]
Richard Laager <rlaager@pidgin.im>
parents:
13336
diff
changeset
|
823 | gtk_widget_set_sensitive(menuitem, imhtml->editable); |
| 13336 | 824 | /* put it after Delete */ |
| 825 | gtk_menu_shell_insert(GTK_MENU_SHELL(menu), menuitem, 5); | |
| 826 | ||
| 827 | g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(clear_formatting_cb), imhtml); | |
| 8931 | 828 | } |
| 829 | ||
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
830 | static char * |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
831 | ucs2_order(gboolean swap) |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
832 | { |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
833 | gboolean be; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
834 | |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
835 | be = G_BYTE_ORDER == G_BIG_ENDIAN; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
836 | be = swap ? be : !be; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
837 | |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
838 | if (be) |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
839 | return "UCS-2BE"; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
840 | else |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
841 | return "UCS-2LE"; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
842 | |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
843 | } |
|
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 | /* 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
|
846 | static gchar * |
| 11586 | 847 | ucs2_to_utf8_with_bom_check(gchar *data, guint len) { |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
848 | char *fromcode = NULL; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
849 | GError *error = NULL; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
850 | guint16 c; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
851 | gchar *utf8_ret; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
852 | |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
853 | /* |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
854 | * Unicode Techinical Report 20 |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
855 | * ( http://www.unicode.org/unicode/reports/tr20/ ) says to treat an |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
856 | * initial 0xfeff (ZWNBSP) as a byte order indicator so that is |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
857 | * 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
|
858 | * order |
|
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 | memcpy(&c, data, 2); |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
862 | switch (c) { |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
863 | case 0xfeff: |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
864 | case 0xfffe: |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
865 | fromcode = ucs2_order(c == 0xfeff); |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
866 | data += 2; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
867 | len -= 2; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
868 | break; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
869 | default: |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
870 | fromcode = "UCS-2"; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
871 | break; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
872 | } |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
873 | |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
874 | 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
|
875 | |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
876 | if (error) { |
| 15884 | 877 | 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
|
878 | g_error_free(error); |
|
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 | return utf8_ret; |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
881 | } |
|
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 | |
| 8061 | 884 | 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
|
885 | 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
|
886 | gboolean primary = (clipboard != clipboard_selection); |
| 8061 | 887 | 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
|
888 | 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
|
889 | 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
|
890 | |
|
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
891 | if (primary) { |
|
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
892 | 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
|
893 | 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
|
894 | 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
|
895 | 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
|
896 | } |
| 8061 | 897 | |
| 898 | if (info == TARGET_HTML) { | |
|
15111
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
899 | char *selection; |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
900 | #ifndef _WIN32 |
| 8907 | 901 | gsize len; |
| 8061 | 902 | GString *str = g_string_new(NULL); |
| 8681 | 903 | if (primary) { |
| 904 | text = gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
| 10013 | 905 | } else |
|
17546
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
906 | text = html_clipboard; |
| 8061 | 907 | |
| 908 | /* Mozilla asks that we start our text/html with the Unicode byte order mark */ | |
| 909 | str = g_string_append_unichar(str, 0xfeff); | |
| 910 | str = g_string_append(str, text); | |
| 911 | str = g_string_append_unichar(str, 0x0000); | |
|
8148
dc970ca129c5
[gaim-migrate @ 8859]
Mohammed Sameer <msameer@users.sourceforge.net>
parents:
8128
diff
changeset
|
912 | 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
|
913 | gtk_selection_data_set(selection_data, gdk_atom_intern("text/html", FALSE), 16, (const guchar *)selection, len); |
| 8061 | 914 | g_string_free(str, TRUE); |
|
15111
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
915 | #else |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
916 | selection = clipboard_html_to_win32(imhtml->clipboard_html_string); |
|
e427dd6f3b7e
[gaim-migrate @ 17833]
Daniel Atallah <datallah@pidgin.im>
parents:
15093
diff
changeset
|
917 | 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
|
918 | #endif |
| 8061 | 919 | g_free(selection); |
| 920 | } else { | |
| 8681 | 921 | if (primary) { |
| 922 | text = gtk_imhtml_get_text(imhtml, &start, &end); | |
| 923 | } else | |
|
17546
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
924 | text = text_clipboard; |
| 8061 | 925 | gtk_selection_data_set_text(selection_data, text, strlen(text)); |
| 926 | } | |
| 8681 | 927 | if (primary) /* This was allocated here */ |
| 928 | g_free(text); | |
| 929 | } | |
| 8061 | 930 | |
| 931 | static void gtk_imhtml_primary_clipboard_clear(GtkClipboard *clipboard, GtkIMHtml *imhtml) | |
| 7749 | 932 | { |
| 8061 | 933 | GtkTextIter insert; |
| 934 | GtkTextIter selection_bound; | |
| 935 | ||
| 936 | gtk_text_buffer_get_iter_at_mark (imhtml->text_buffer, &insert, | |
| 937 | gtk_text_buffer_get_mark (imhtml->text_buffer, "insert")); | |
| 938 | gtk_text_buffer_get_iter_at_mark (imhtml->text_buffer, &selection_bound, | |
| 939 | gtk_text_buffer_get_mark (imhtml->text_buffer, "selection_bound")); | |
| 940 | ||
| 941 | if (!gtk_text_iter_equal (&insert, &selection_bound)) | |
| 942 | gtk_text_buffer_move_mark (imhtml->text_buffer, | |
| 943 | gtk_text_buffer_get_mark (imhtml->text_buffer, "selection_bound"), | |
| 944 | &insert); | |
| 7749 | 945 | } |
| 7742 | 946 | |
|
17546
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
947 | 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
|
948 | 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
|
949 | { |
|
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
950 | 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
|
951 | } |
|
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
952 | |
| 8677 | 953 | static void copy_clipboard_cb(GtkIMHtml *imhtml, gpointer unused) |
| 7749 | 954 | { |
| 8681 | 955 | 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
|
956 | 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
|
957 | 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
|
958 | 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
|
959 | 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
|
960 | 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
|
961 | (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
|
962 | (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
|
963 | |
| 8681 | 964 | g_free(imhtml->clipboard_html_string); |
| 965 | g_free(imhtml->clipboard_text_string); | |
|
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
|
966 | |
|
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 | 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
|
968 | 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
|
969 | |
|
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
970 | 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
|
971 | 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
|
972 | |
| 8681 | 973 | } |
| 974 | ||
| 8061 | 975 | g_signal_stop_emission_by_name(imhtml, "copy-clipboard"); |
| 976 | } | |
| 977 | ||
| 8698 | 978 | static void cut_clipboard_cb(GtkIMHtml *imhtml, gpointer unused) |
| 979 | { | |
| 980 | 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
|
981 | 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
|
982 | 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
|
983 | 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
|
984 | 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
|
985 | 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
|
986 | (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
|
987 | (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
|
988 | |
| 8698 | 989 | g_free(imhtml->clipboard_html_string); |
| 990 | g_free(imhtml->clipboard_text_string); | |
|
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
|
991 | |
|
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 | 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
|
993 | 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
|
994 | |
|
17546
51b1c1e2c3fe
Maintain global poitners to the clipboard selection text, with the aim of
Sean Egan <seanegan@pidgin.im>
parents:
17406
diff
changeset
|
995 | 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
|
996 | 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
|
997 | |
|
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 | 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
|
999 | gtk_text_buffer_delete_selection(imhtml->text_buffer, FALSE, FALSE); |
| 8698 | 1000 | } |
| 1001 | ||
| 1002 | g_signal_stop_emission_by_name(imhtml, "cut-clipboard"); | |
| 1003 | } | |
| 1004 | ||
| 8931 | 1005 | static void imhtml_paste_insert(GtkIMHtml *imhtml, const char *text, gboolean plaintext) |
| 1006 | { | |
| 1007 | GtkTextIter iter; | |
| 9465 | 1008 | GtkIMHtmlOptions flags = plaintext ? 0 : (GTK_IMHTML_NO_NEWLINE | GTK_IMHTML_NO_COMMENTS); |
| 8931 | 1009 | |
| 9028 | 1010 | if (gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) |
| 1011 | gtk_text_buffer_delete_selection(imhtml->text_buffer, TRUE, TRUE); | |
| 1012 | ||
| 8931 | 1013 | gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, gtk_text_buffer_get_insert(imhtml->text_buffer)); |
| 1014 | if (!imhtml->wbfo && !plaintext) | |
| 1015 | gtk_imhtml_close_tags(imhtml, &iter); | |
| 1016 | ||
| 1017 | gtk_imhtml_insert_html_at_iter(imhtml, text, flags, &iter); | |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
1018 | if (!imhtml->wbfo && !plaintext) |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
1019 | gtk_imhtml_close_tags(imhtml, &iter); |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
1020 | gtk_text_buffer_move_mark_by_name(imhtml->text_buffer, "insert", &iter); |
| 8931 | 1021 | gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(imhtml), gtk_text_buffer_get_insert(imhtml->text_buffer), |
| 1022 | 0, FALSE, 0.0, 0.0); | |
| 1023 | } | |
| 1024 | ||
| 1025 | static void paste_plaintext_received_cb (GtkClipboard *clipboard, const gchar *text, gpointer data) | |
| 1026 | { | |
| 1027 | char *tmp; | |
| 1028 | ||
| 1029 | if (text == NULL) | |
| 1030 | return; | |
| 1031 | ||
|
10732
5e314ab498bf
[gaim-migrate @ 12334]
Richard Laager <rlaager@pidgin.im>
parents:
10699
diff
changeset
|
1032 | tmp = g_markup_escape_text(text, -1); |
| 8931 | 1033 | imhtml_paste_insert(data, tmp, TRUE); |
| 1034 | g_free(tmp); | |
| 1035 | } | |
| 1036 | ||
| 8061 | 1037 | static void paste_received_cb (GtkClipboard *clipboard, GtkSelectionData *selection_data, gpointer data) |
| 1038 | { | |
| 1039 | char *text; | |
| 1040 | GtkIMHtml *imhtml = data; | |
| 7809 | 1041 | |
|
8123
e09c75f511c2
[gaim-migrate @ 8827]
Mark Doliner <markdoliner@pidgin.im>
parents:
8120
diff
changeset
|
1042 | if (!gtk_text_view_get_editable(GTK_TEXT_VIEW(imhtml))) |
|
8105
54ea897b764e
[gaim-migrate @ 8805]
Nathan Fredrickson <nathan@silverorange.com>
parents:
8091
diff
changeset
|
1043 | return; |
|
54ea897b764e
[gaim-migrate @ 8805]
Nathan Fredrickson <nathan@silverorange.com>
parents:
8091
diff
changeset
|
1044 | |
| 8061 | 1045 | if (selection_data->length < 0) { |
| 8931 | 1046 | gtk_clipboard_request_text(clipboard, paste_plaintext_received_cb, imhtml); |
| 1047 | return; | |
| 8061 | 1048 | } else { |
| 8719 | 1049 | #if 0 |
| 1050 | /* Here's some debug code, for figuring out what sent to us over the clipboard. */ | |
| 1051 | { | |
| 1052 | int i; | |
| 1053 | ||
| 15884 | 1054 | purple_debug_misc("gtkimhtml", "In paste_received_cb():\n\tformat = %d, length = %d\n\t", |
| 8719 | 1055 | selection_data->format, selection_data->length); |
| 1056 | ||
| 1057 | for (i = 0; i < (/*(selection_data->format / 8) **/ selection_data->length); i++) { | |
| 1058 | if ((i % 70) == 0) | |
| 1059 | printf("\n\t"); | |
| 1060 | if (selection_data->data[i] == '\0') | |
| 1061 | printf("."); | |
| 1062 | else | |
| 1063 | printf("%c", selection_data->data[i]); | |
| 1064 | } | |
| 1065 | printf("\n"); | |
| 1066 | } | |
| 1067 | #endif | |
| 1068 | text = g_malloc(selection_data->length); | |
| 1069 | memcpy(text, selection_data->data, selection_data->length); | |
| 7766 | 1070 | } |
| 8061 | 1071 | |
| 8869 | 1072 | if (selection_data->length >= 2 && |
| 1073 | (*(guint16 *)text == 0xfeff || *(guint16 *)text == 0xfffe)) { | |
| 1074 | /* This is UCS-2 */ | |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
1075 | char *utf8 = ucs2_to_utf8_with_bom_check(text, selection_data->length); |
| 8061 | 1076 | g_free(text); |
| 1077 | text = utf8; | |
| 8698 | 1078 | if (!text) { |
| 15884 | 1079 | purple_debug_warning("gtkimhtml", "g_convert from UCS-2 failed in paste_received_cb\n"); |
| 8698 | 1080 | return; |
| 1081 | } | |
| 8061 | 1082 | } |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
1083 | |
| 8698 | 1084 | if (!(*text) || !g_utf8_validate(text, -1, NULL)) { |
| 15884 | 1085 | purple_debug_warning("gtkimhtml", "empty string or invalid UTF-8 in paste_received_cb\n"); |
| 8698 | 1086 | g_free(text); |
| 1087 | return; | |
| 1088 | } | |
| 1089 | ||
| 8931 | 1090 | imhtml_paste_insert(imhtml, text, FALSE); |
| 8681 | 1091 | g_free(text); |
| 8061 | 1092 | } |
| 1093 | ||
| 1094 | static void paste_clipboard_cb(GtkIMHtml *imhtml, gpointer blah) | |
| 1095 | { | |
| 8931 | 1096 | #ifdef _WIN32 |
| 1097 | /* 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
|
1098 | clipboard before we try to paste from the GTK buffer */ |
|
5d81e32bd258
[gaim-migrate @ 12622]
Daniel Atallah <datallah@pidgin.im>
parents:
10900
diff
changeset
|
1099 | if (!clipboard_paste_html_win32(imhtml)) { |
| 8931 | 1100 | #endif |
| 8061 | 1101 | GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD); |
| 1102 | gtk_clipboard_request_contents(clipboard, gdk_atom_intern("text/html", FALSE), | |
| 1103 | paste_received_cb, imhtml); | |
| 8931 | 1104 | #ifdef _WIN32 |
| 1105 | } | |
| 1106 | #endif | |
| 8061 | 1107 | g_signal_stop_emission_by_name(imhtml, "paste-clipboard"); |
| 7766 | 1108 | } |
| 1109 | ||
| 8677 | 1110 | static void imhtml_realized_remove_primary(GtkIMHtml *imhtml, gpointer unused) |
| 1111 | { | |
| 1112 | gtk_text_buffer_remove_selection_clipboard(GTK_IMHTML(imhtml)->text_buffer, | |
| 1113 | gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY)); | |
| 1114 | ||
| 1115 | } | |
| 1116 | ||
|
8740
098a43943bba
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
1117 | static void imhtml_destroy_add_primary(GtkIMHtml *imhtml, gpointer unused) |
|
098a43943bba
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
1118 | { |
|
098a43943bba
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
1119 | gtk_text_buffer_add_selection_clipboard(GTK_IMHTML(imhtml)->text_buffer, |
|
098a43943bba
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
1120 | gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY)); |
|
098a43943bba
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
1121 | } |
| 8677 | 1122 | |
| 1123 | static void mark_set_so_update_selection_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, GtkIMHtml *imhtml) | |
| 1124 | { | |
| 1125 | if (gtk_text_buffer_get_selection_bounds(buffer, NULL, NULL)) { | |
| 1126 | gtk_clipboard_set_with_owner(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY), | |
| 1127 | selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry), | |
| 1128 | (GtkClipboardGetFunc)gtk_imhtml_clipboard_get, | |
| 1129 | (GtkClipboardClearFunc)gtk_imhtml_primary_clipboard_clear, G_OBJECT(imhtml)); | |
| 1130 | } | |
| 1131 | } | |
| 1132 | ||
| 1133 | static gboolean gtk_imhtml_button_press_event(GtkIMHtml *imhtml, GdkEventButton *event, gpointer unused) | |
| 7346 | 1134 | { |
| 8677 | 1135 | if (event->button == 2) { |
| 1136 | int x, y; | |
| 1137 | GtkTextIter iter; | |
| 1138 | GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY); | |
| 1139 | ||
| 1140 | if (!imhtml->editable) | |
| 1141 | return FALSE; | |
| 1142 | ||
| 1143 | gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(imhtml), | |
| 1144 | GTK_TEXT_WINDOW_TEXT, | |
| 1145 | event->x, | |
| 1146 | event->y, | |
| 1147 | &x, | |
| 1148 | &y); | |
| 1149 | gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, x, y); | |
| 1150 | gtk_text_buffer_place_cursor(imhtml->text_buffer, &iter); | |
| 1151 | ||
| 1152 | gtk_clipboard_request_contents(clipboard, gdk_atom_intern("text/html", FALSE), | |
| 1153 | paste_received_cb, imhtml); | |
| 1154 | ||
| 1155 | return TRUE; | |
| 1156 | } | |
| 1157 | ||
| 7346 | 1158 | return FALSE; |
| 1159 | } | |
| 4263 | 1160 | |
|
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
|
1161 | 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
|
1162 | 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
|
1163 | 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
|
1164 | 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
|
1165 | |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1166 | 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
|
1167 | } |
|
5e73968467e0
Undo/Redo in GtkImHtml from GtkSourceView. This may not be adaquate enough for us.
Sean Egan <seanegan@pidgin.im>
parents:
17288
diff
changeset
|
1168 | |
|
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_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
|
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_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
|
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 | |
| 10108 | 1178 | static gboolean imhtml_message_send(GtkIMHtml *imhtml) |
| 1179 | { | |
| 1180 | return FALSE; | |
| 1181 | } | |
| 1182 | ||
| 10100 | 1183 | static void imhtml_toggle_format(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons) |
| 1184 | { | |
|
10699
7f9fa4f13758
[gaim-migrate @ 12256]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10695
diff
changeset
|
1185 | /* since this function is the handler for the formatting keystrokes, |
|
7f9fa4f13758
[gaim-migrate @ 12256]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10695
diff
changeset
|
1186 | 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
|
1187 | buttons &= imhtml->format_functions; |
|
10699
7f9fa4f13758
[gaim-migrate @ 12256]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10695
diff
changeset
|
1188 | |
| 10100 | 1189 | switch (buttons) { |
| 1190 | case GTK_IMHTML_BOLD: | |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
1191 | imhtml_toggle_bold(imhtml); |
| 10100 | 1192 | break; |
| 1193 | case GTK_IMHTML_ITALIC: | |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
1194 | imhtml_toggle_italic(imhtml); |
| 10100 | 1195 | break; |
| 1196 | case GTK_IMHTML_UNDERLINE: | |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
1197 | imhtml_toggle_underline(imhtml); |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
1198 | break; |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
1199 | case GTK_IMHTML_STRIKE: |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
1200 | imhtml_toggle_strike(imhtml); |
| 10100 | 1201 | break; |
| 1202 | case GTK_IMHTML_SHRINK: | |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
1203 | imhtml_font_shrink(imhtml); |
| 10100 | 1204 | break; |
| 1205 | case GTK_IMHTML_GROW: | |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
1206 | imhtml_font_grow(imhtml); |
| 10100 | 1207 | break; |
| 1208 | default: | |
| 1209 | break; | |
| 1210 | } | |
| 1211 | } | |
| 4032 | 1212 | |
| 1213 | static void | |
| 1214 | gtk_imhtml_finalize (GObject *object) | |
| 1215 | { | |
| 1216 | GtkIMHtml *imhtml = GTK_IMHTML(object); | |
| 4895 | 1217 | GList *scalables; |
| 8962 | 1218 | GSList *l; |
| 8061 | 1219 | |
| 10798 | 1220 | if (imhtml->scroll_src) |
| 1221 | g_source_remove(imhtml->scroll_src); | |
| 1222 | if (imhtml->scroll_time) | |
| 1223 | g_timer_destroy(imhtml->scroll_time); | |
| 1224 | ||
| 4138 | 1225 | g_hash_table_destroy(imhtml->smiley_data); |
| 4032 | 1226 | gtk_smiley_tree_destroy(imhtml->default_smilies); |
| 4138 | 1227 | gdk_cursor_unref(imhtml->hand_cursor); |
| 1228 | gdk_cursor_unref(imhtml->arrow_cursor); | |
| 8061 | 1229 | gdk_cursor_unref(imhtml->text_cursor); |
| 8677 | 1230 | |
| 4735 | 1231 | if(imhtml->tip_window){ |
| 1232 | gtk_widget_destroy(imhtml->tip_window); | |
| 1233 | } | |
| 1234 | if(imhtml->tip_timer) | |
| 1235 | gtk_timeout_remove(imhtml->tip_timer); | |
| 1236 | ||
| 4895 | 1237 | for(scalables = imhtml->scalables; scalables; scalables = scalables->next) { |
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
1238 | struct scalable_data *sd = scalables->data; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
1239 | GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(sd->scalable); |
| 4895 | 1240 | scale->free(scale); |
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
1241 | g_free(sd); |
| 4895 | 1242 | } |
| 7991 | 1243 | |
| 8962 | 1244 | for (l = imhtml->im_images; l; l = l->next) { |
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
1245 | struct im_image_data *img_data = l->data; |
| 8962 | 1246 | if (imhtml->funcs->image_unref) |
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
1247 | imhtml->funcs->image_unref(img_data->id); |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
1248 | g_free(img_data); |
| 8962 | 1249 | } |
| 1250 | ||
| 4895 | 1251 | g_list_free(imhtml->scalables); |
| 8962 | 1252 | 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
|
1253 | g_queue_free(imhtml->animations); |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
1254 | g_free(imhtml->protocol_name); |
|
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
1255 | 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
|
1256 | g_object_unref(imhtml->undo_manager); |
| 4032 | 1257 | 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
|
1258 | 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
|
1259 | 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
|
1260 | 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
|
1261 | (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
|
1262 | (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
|
1263 | |
| 4032 | 1264 | } |
| 1428 | 1265 | |
|
10814
7e17cb56b019
[gaim-migrate @ 12468]
Luke Schierer <lschiere@pidgin.im>
parents:
10799
diff
changeset
|
1266 | /* Boring GTK+ stuff */ |
| 8519 | 1267 | static void gtk_imhtml_class_init (GtkIMHtmlClass *klass) |
| 1428 | 1268 | { |
| 9007 | 1269 | GtkWidgetClass *widget_class = (GtkWidgetClass *) klass; |
| 3922 | 1270 | GtkObjectClass *object_class; |
| 10100 | 1271 | GtkBindingSet *binding_set; |
| 4032 | 1272 | GObjectClass *gobject_class; |
| 8519 | 1273 | object_class = (GtkObjectClass*) klass; |
| 1274 | gobject_class = (GObjectClass*) klass; | |
| 4032 | 1275 | parent_class = gtk_type_class(GTK_TYPE_TEXT_VIEW); |
| 4417 | 1276 | signals[URL_CLICKED] = g_signal_new("url_clicked", |
| 1277 | G_TYPE_FROM_CLASS(gobject_class), | |
| 1278 | G_SIGNAL_RUN_FIRST, | |
| 1279 | G_STRUCT_OFFSET(GtkIMHtmlClass, url_clicked), | |
| 1280 | NULL, | |
| 1281 | 0, | |
| 1282 | g_cclosure_marshal_VOID__POINTER, | |
| 1283 | G_TYPE_NONE, 1, | |
| 1284 | G_TYPE_POINTER); | |
| 8506 | 1285 | signals[BUTTONS_UPDATE] = g_signal_new("format_buttons_update", |
| 8420 | 1286 | G_TYPE_FROM_CLASS(gobject_class), |
| 1287 | G_SIGNAL_RUN_FIRST, | |
| 1288 | G_STRUCT_OFFSET(GtkIMHtmlClass, buttons_update), | |
| 1289 | NULL, | |
| 1290 | 0, | |
|
10076
1ccc0286a4ae
[gaim-migrate @ 11057]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10062
diff
changeset
|
1291 | g_cclosure_marshal_VOID__INT, |
| 8420 | 1292 | G_TYPE_NONE, 1, |
| 1293 | G_TYPE_INT); | |
| 1294 | signals[TOGGLE_FORMAT] = g_signal_new("format_function_toggle", | |
| 1295 | G_TYPE_FROM_CLASS(gobject_class), | |
| 10100 | 1296 | G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, |
| 8420 | 1297 | G_STRUCT_OFFSET(GtkIMHtmlClass, toggle_format), |
| 1298 | NULL, | |
| 1299 | 0, | |
|
10076
1ccc0286a4ae
[gaim-migrate @ 11057]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10062
diff
changeset
|
1300 | g_cclosure_marshal_VOID__INT, |
|
1ccc0286a4ae
[gaim-migrate @ 11057]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10062
diff
changeset
|
1301 | G_TYPE_NONE, 1, |
| 8420 | 1302 | G_TYPE_INT); |
| 8427 | 1303 | signals[CLEAR_FORMAT] = g_signal_new("format_function_clear", |
| 1304 | G_TYPE_FROM_CLASS(gobject_class), | |
|
11385
38ca1438e055
[gaim-migrate @ 13612]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11315
diff
changeset
|
1305 | G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, |
| 8427 | 1306 | G_STRUCT_OFFSET(GtkIMHtmlClass, clear_format), |
| 1307 | NULL, | |
| 1308 | 0, | |
| 10100 | 1309 | g_cclosure_marshal_VOID__VOID, |
| 1310 | G_TYPE_NONE, 0); | |
| 8506 | 1311 | signals[UPDATE_FORMAT] = g_signal_new("format_function_update", |
| 10100 | 1312 | G_TYPE_FROM_CLASS(gobject_class), |
| 1313 | G_SIGNAL_RUN_FIRST, | |
| 1314 | G_STRUCT_OFFSET(GtkIMHtmlClass, update_format), | |
| 1315 | NULL, | |
| 1316 | 0, | |
| 1317 | g_cclosure_marshal_VOID__VOID, | |
| 1318 | G_TYPE_NONE, 0); | |
| 10108 | 1319 | signals[MESSAGE_SEND] = g_signal_new("message_send", |
| 1320 | G_TYPE_FROM_CLASS(gobject_class), | |
| 1321 | G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, | |
| 1322 | G_STRUCT_OFFSET(GtkIMHtmlClass, message_send), | |
| 1323 | NULL, | |
| 1324 | 0, g_cclosure_marshal_VOID__VOID, | |
| 1325 | 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
|
1326 | 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
|
1327 | 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
|
1328 | 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
|
1329 | 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
|
1330 | 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
|
1331 | 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
|
1332 | 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
|
1333 | 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
|
1334 | 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
|
1335 | 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
|
1336 | 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
|
1337 | 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
|
1338 | 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
|
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 | 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
|
1341 | 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
|
1342 | 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
|
1343 | 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
|
1344 | |
|
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 | |
| 10100 | 1346 | |
| 1347 | klass->toggle_format = imhtml_toggle_format; | |
| 10108 | 1348 | klass->message_send = imhtml_message_send; |
|
12672
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
1349 | 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
|
1350 | 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
|
1351 | klass->redo = gtk_imhtml_redo; |
|
10184
543c9a84ce16
[gaim-migrate @ 11299]
Mark Doliner <markdoliner@pidgin.im>
parents:
10169
diff
changeset
|
1352 | |
| 4032 | 1353 | gobject_class->finalize = gtk_imhtml_finalize; |
|
10184
543c9a84ce16
[gaim-migrate @ 11299]
Mark Doliner <markdoliner@pidgin.im>
parents:
10169
diff
changeset
|
1354 | widget_class->drag_motion = gtk_text_view_drag_motion; |
| 10692 | 1355 | widget_class->expose_event = gtk_imhtml_expose_event; |
| 9007 | 1356 | gtk_widget_class_install_style_property(widget_class, g_param_spec_boxed("hyperlink-color", |
| 1357 | _("Hyperlink color"), | |
| 1358 | _("Color to draw hyperlinks."), | |
| 1359 | GDK_TYPE_COLOR, G_PARAM_READABLE)); | |
| 10799 | 1360 | gtk_widget_class_install_style_property(widget_class, g_param_spec_boxed("hyperlink-prelight-color", |
| 1361 | _("Hyperlink prelight color"), | |
| 1362 | _("Color to draw hyperlinks when mouse is over them."), | |
| 1363 | GDK_TYPE_COLOR, G_PARAM_READABLE)); | |
| 10100 | 1364 | |
| 1365 | binding_set = gtk_binding_set_by_class (parent_class); | |
| 10110 | 1366 | gtk_binding_entry_add_signal (binding_set, GDK_b, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_BOLD); |
| 10100 | 1367 | gtk_binding_entry_add_signal (binding_set, GDK_i, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_ITALIC); |
| 1368 | gtk_binding_entry_add_signal (binding_set, GDK_u, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_UNDERLINE); | |
| 1369 | gtk_binding_entry_add_signal (binding_set, GDK_plus, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_GROW); | |
| 1370 | gtk_binding_entry_add_signal (binding_set, GDK_equal, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_GROW); | |
| 1371 | gtk_binding_entry_add_signal (binding_set, GDK_minus, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_SHRINK); | |
| 10108 | 1372 | binding_set = gtk_binding_set_by_class(klass); |
|
11385
38ca1438e055
[gaim-migrate @ 13612]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11315
diff
changeset
|
1373 | gtk_binding_entry_add_signal (binding_set, GDK_r, GDK_CONTROL_MASK, "format_function_clear", 0); |
| 10108 | 1374 | gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0, "message_send", 0); |
| 1375 | 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
|
1376 | 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
|
1377 | 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
|
1378 | 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
|
1379 | |
| 1428 | 1380 | } |
| 1381 | ||
| 3922 | 1382 | static void gtk_imhtml_init (GtkIMHtml *imhtml) |
| 1428 | 1383 | { |
| 3922 | 1384 | GtkTextIter iter; |
| 1385 | 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
|
1386 | imhtml->undo_manager = gtk_source_undo_manager_new(imhtml->text_buffer); |
| 3922 | 1387 | gtk_text_buffer_get_end_iter (imhtml->text_buffer, &iter); |
| 1388 | 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
|
1389 | gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(imhtml), GTK_WRAP_WORD_CHAR); |
| 3922 | 1390 | gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(imhtml), 5); |
| 8677 | 1391 | gtk_text_view_set_left_margin(GTK_TEXT_VIEW(imhtml), 2); |
| 1392 | gtk_text_view_set_right_margin(GTK_TEXT_VIEW(imhtml), 2); | |
| 8061 | 1393 | /*gtk_text_view_set_indent(GTK_TEXT_VIEW(imhtml), -15);*/ |
| 3922 | 1394 | /*gtk_text_view_set_justification(GTK_TEXT_VIEW(imhtml), GTK_JUSTIFY_FILL);*/ |
| 8061 | 1395 | |
| 3922 | 1396 | /* These tags will be used often and can be reused--we create them on init and then apply them by name |
| 8932 | 1397 | * other tags (color, size, face, etc.) will have to be created and applied dynamically |
| 9924 | 1398 | * Note that even though we created SUB, SUP, and PRE tags here, we don't really |
| 8932 | 1399 | * apply them anywhere yet. */ |
| 3922 | 1400 | gtk_text_buffer_create_tag(imhtml->text_buffer, "BOLD", "weight", PANGO_WEIGHT_BOLD, NULL); |
| 1401 | gtk_text_buffer_create_tag(imhtml->text_buffer, "ITALICS", "style", PANGO_STYLE_ITALIC, NULL); | |
| 1402 | gtk_text_buffer_create_tag(imhtml->text_buffer, "UNDERLINE", "underline", PANGO_UNDERLINE_SINGLE, NULL); | |
| 1403 | gtk_text_buffer_create_tag(imhtml->text_buffer, "STRIKE", "strikethrough", TRUE, NULL); | |
| 1404 | gtk_text_buffer_create_tag(imhtml->text_buffer, "SUB", "rise", -5000, NULL); | |
| 1405 | gtk_text_buffer_create_tag(imhtml->text_buffer, "SUP", "rise", 5000, NULL); | |
| 1406 | gtk_text_buffer_create_tag(imhtml->text_buffer, "PRE", "family", "Monospace", NULL); | |
| 7295 | 1407 | gtk_text_buffer_create_tag(imhtml->text_buffer, "search", "background", "#22ff00", "weight", "bold", NULL); |
| 8677 | 1408 | |
| 3922 | 1409 | /* When hovering over a link, we show the hand cursor--elsewhere we show the plain ol' pointer cursor */ |
| 1410 | imhtml->hand_cursor = gdk_cursor_new (GDK_HAND2); | |
| 1411 | imhtml->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR); | |
| 8061 | 1412 | imhtml->text_cursor = gdk_cursor_new (GDK_XTERM); |
| 2993 | 1413 | |
|
6124
322206d79652
[gaim-migrate @ 6598]
Mark Doliner <markdoliner@pidgin.im>
parents:
6066
diff
changeset
|
1414 | imhtml->show_comments = TRUE; |
| 4253 | 1415 | |
| 4892 | 1416 | imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 4902 | 1417 | g_free, (GDestroyNotify)gtk_smiley_tree_destroy); |
| 4032 | 1418 | imhtml->default_smilies = gtk_smiley_tree_new(); |
| 4735 | 1419 | |
|
4944
032dac83798e
[gaim-migrate @ 5278]
Robert McQueen <robot101@debian.org>
parents:
4926
diff
changeset
|
1420 | g_signal_connect(G_OBJECT(imhtml), "size-allocate", G_CALLBACK(gtk_size_allocate_cb), NULL); |
| 4735 | 1421 | 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
|
1422 | 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
|
1423 | 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
|
1424 | #if (!GTK_CHECK_VERSION(2,2,0)) |
|
fb5b88957742
[gaim-migrate @ 12516]
Richard Laager <rlaager@pidgin.im>
parents:
10834
diff
changeset
|
1425 | /* See the comment for gtk_key_pressed_cb */ |
| 6066 | 1426 | 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
|
1427 | #endif |
| 8677 | 1428 | g_signal_connect(G_OBJECT(imhtml), "button_press_event", G_CALLBACK(gtk_imhtml_button_press_event), NULL); |
| 1429 | 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
|
1430 | g_signal_connect(G_OBJECT(imhtml->text_buffer), "delete_range", G_CALLBACK(delete_cb), imhtml); |
| 8061 | 1431 | g_signal_connect_after(G_OBJECT(imhtml->text_buffer), "insert-text", G_CALLBACK(insert_cb), imhtml); |
| 10169 | 1432 | g_signal_connect_after(G_OBJECT(imhtml->text_buffer), "insert-child-anchor", G_CALLBACK(insert_ca_cb), imhtml); |
| 8091 | 1433 | gtk_drag_dest_set(GTK_WIDGET(imhtml), 0, |
| 1434 | link_drag_drop_targets, sizeof(link_drag_drop_targets) / sizeof(GtkTargetEntry), | |
| 1435 | GDK_ACTION_COPY); | |
| 1436 | g_signal_connect(G_OBJECT(imhtml), "drag_data_received", G_CALLBACK(gtk_imhtml_link_drag_rcv_cb), imhtml); | |
| 9300 | 1437 | g_signal_connect(G_OBJECT(imhtml), "drag_drop", G_CALLBACK(gtk_imhtml_link_drop_cb), imhtml); |
| 8091 | 1438 | |
| 7353 | 1439 | g_signal_connect(G_OBJECT(imhtml), "copy-clipboard", G_CALLBACK(copy_clipboard_cb), NULL); |
| 8698 | 1440 | g_signal_connect(G_OBJECT(imhtml), "cut-clipboard", G_CALLBACK(cut_clipboard_cb), NULL); |
| 8061 | 1441 | g_signal_connect(G_OBJECT(imhtml), "paste-clipboard", G_CALLBACK(paste_clipboard_cb), NULL); |
| 8677 | 1442 | 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
|
1443 | g_signal_connect(G_OBJECT(imhtml), "unrealize", G_CALLBACK(imhtml_destroy_add_primary), NULL); |
| 8677 | 1444 | |
| 1445 | g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set", | |
| 1446 | G_CALLBACK(mark_set_so_update_selection_cb), imhtml); | |
| 1447 | ||
|
10946
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
1448 | gtk_widget_add_events(GTK_WIDGET(imhtml), |
|
63a41710fc94
[gaim-migrate @ 12742]
Daniel Atallah <datallah@pidgin.im>
parents:
10936
diff
changeset
|
1449 | GDK_LEAVE_NOTIFY_MASK | GDK_ENTER_NOTIFY_MASK); |
| 4735 | 1450 | |
| 8681 | 1451 | imhtml->clipboard_text_string = NULL; |
| 1452 | imhtml->clipboard_html_string = NULL; | |
| 1453 | ||
| 4735 | 1454 | imhtml->tip = NULL; |
| 1455 | imhtml->tip_timer = 0; | |
| 1456 | imhtml->tip_window = NULL; | |
| 4895 | 1457 | |
| 8677 | 1458 | imhtml->edit.bold = FALSE; |
| 1459 | imhtml->edit.italic = FALSE; | |
| 1460 | imhtml->edit.underline = FALSE; | |
| 8061 | 1461 | imhtml->edit.forecolor = NULL; |
| 1462 | imhtml->edit.backcolor = NULL; | |
| 1463 | imhtml->edit.fontface = NULL; | |
| 8677 | 1464 | imhtml->edit.fontsize = 0; |
| 1465 | imhtml->edit.link = NULL; | |
| 1466 | ||
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
1467 | |
| 4895 | 1468 | 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
|
1469 | imhtml->animations = g_queue_new(); |
| 8061 | 1470 | gtk_imhtml_set_editable(imhtml, FALSE); |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
1471 | g_signal_connect(G_OBJECT(imhtml), "populate-popup", |
| 8931 | 1472 | G_CALLBACK(hijack_menu_cb), NULL); |
| 2993 | 1473 | } |
| 1474 | ||
| 3922 | 1475 | GtkWidget *gtk_imhtml_new(void *a, void *b) |
| 1428 | 1476 | { |
| 4635 | 1477 | return GTK_WIDGET(g_object_new(gtk_imhtml_get_type(), NULL)); |
| 1428 | 1478 | } |
| 1479 | ||
| 9037 | 1480 | GType gtk_imhtml_get_type() |
| 1428 | 1481 | { |
| 9037 | 1482 | static GType imhtml_type = 0; |
| 1428 | 1483 | |
| 1484 | if (!imhtml_type) { | |
| 9037 | 1485 | static const GTypeInfo imhtml_info = { |
| 4635 | 1486 | sizeof(GtkIMHtmlClass), |
| 1487 | NULL, | |
| 1488 | NULL, | |
| 1489 | (GClassInitFunc) gtk_imhtml_class_init, | |
| 1490 | NULL, | |
| 1491 | NULL, | |
| 1428 | 1492 | sizeof (GtkIMHtml), |
| 4635 | 1493 | 0, |
|
12600
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
12553
diff
changeset
|
1494 | (GInstanceInitFunc) gtk_imhtml_init, |
|
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
12553
diff
changeset
|
1495 | NULL |
| 1428 | 1496 | }; |
| 4635 | 1497 | |
| 1498 | imhtml_type = g_type_register_static(gtk_text_view_get_type(), | |
| 1499 | "GtkIMHtml", &imhtml_info, 0); | |
| 1428 | 1500 | } |
| 1501 | ||
| 1502 | return imhtml_type; | |
| 1503 | } | |
| 1504 | ||
| 4417 | 1505 | struct url_data { |
| 1506 | GObject *object; | |
| 1507 | gchar *url; | |
| 1508 | }; | |
| 1509 | ||
| 8677 | 1510 | static void url_data_destroy(gpointer mydata) |
| 1511 | { | |
| 1512 | struct url_data *data = mydata; | |
| 1513 | g_object_unref(data->object); | |
| 1514 | g_free(data->url); | |
| 1515 | g_free(data); | |
| 1516 | } | |
| 1517 | ||
| 4417 | 1518 | static void url_open(GtkWidget *w, struct url_data *data) { |
| 1519 | if(!data) return; | |
| 8061 | 1520 | g_signal_emit(data->object, signals[URL_CLICKED], 0, data->url); |
| 7988 | 1521 | |
| 4417 | 1522 | } |
|
5582
2e5da5db947b
[gaim-migrate @ 5986]
Robert McQueen <robot101@debian.org>
parents:
5367
diff
changeset
|
1523 | |
| 4417 | 1524 | static void url_copy(GtkWidget *w, gchar *url) { |
| 1525 | GtkClipboard *clipboard; | |
| 1526 | ||
| 8931 | 1527 | clipboard = gtk_widget_get_clipboard(w, GDK_SELECTION_PRIMARY); |
| 4417 | 1528 | gtk_clipboard_set_text(clipboard, url, -1); |
|
5582
2e5da5db947b
[gaim-migrate @ 5986]
Robert McQueen <robot101@debian.org>
parents:
5367
diff
changeset
|
1529 | |
| 8931 | 1530 | clipboard = gtk_widget_get_clipboard(w, GDK_SELECTION_CLIPBOARD); |
|
5582
2e5da5db947b
[gaim-migrate @ 5986]
Robert McQueen <robot101@debian.org>
parents:
5367
diff
changeset
|
1531 | gtk_clipboard_set_text(clipboard, url, -1); |
| 4417 | 1532 | } |
| 1533 | ||
| 1534 | /* The callback for an event on a link tag. */ | |
|
10871
c0282a4f2250
[gaim-migrate @ 12558]
Mark Doliner <markdoliner@pidgin.im>
parents:
10865
diff
changeset
|
1535 | static gboolean tag_event(GtkTextTag *tag, GObject *imhtml, GdkEvent *event, GtkTextIter *arg2, gpointer unused) { |
| 4417 | 1536 | GdkEventButton *event_button = (GdkEventButton *) event; |
| 8061 | 1537 | if (GTK_IMHTML(imhtml)->editable) |
| 1538 | return FALSE; | |
| 3922 | 1539 | if (event->type == GDK_BUTTON_RELEASE) { |
| 8957 | 1540 | if ((event_button->button == 1) || (event_button->button == 2)) { |
| 4417 | 1541 | GtkTextIter start, end; |
| 1542 | /* we shouldn't open a URL if the user has selected something: */ | |
| 8677 | 1543 | if (gtk_text_buffer_get_selection_bounds( |
| 1544 | gtk_text_iter_get_buffer(arg2), &start, &end)) | |
| 4417 | 1545 | return FALSE; |
| 1546 | ||
| 1547 | /* A link was clicked--we emit the "url_clicked" signal | |
| 1548 | * with the URL as the argument */ | |
| 8677 | 1549 | g_object_ref(G_OBJECT(tag)); |
| 1550 | g_signal_emit(imhtml, signals[URL_CLICKED], 0, g_object_get_data(G_OBJECT(tag), "link_url")); | |
| 1551 | g_object_unref(G_OBJECT(tag)); | |
| 4417 | 1552 | return FALSE; |
| 1553 | } else if(event_button->button == 3) { | |
| 4745 | 1554 | GtkWidget *img, *item, *menu; |
| 4417 | 1555 | struct url_data *tempdata = g_new(struct url_data, 1); |
| 5091 | 1556 | tempdata->object = g_object_ref(imhtml); |
| 8677 | 1557 | tempdata->url = g_strdup(g_object_get_data(G_OBJECT(tag), "link_url")); |
| 4745 | 1558 | |
| 5091 | 1559 | /* Don't want the tooltip around if user right-clicked on link */ |
| 1560 | if (GTK_IMHTML(imhtml)->tip_window) { | |
| 1561 | gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); | |
| 1562 | GTK_IMHTML(imhtml)->tip_window = NULL; | |
| 1563 | } | |
| 1564 | if (GTK_IMHTML(imhtml)->tip_timer) { | |
| 1565 | g_source_remove(GTK_IMHTML(imhtml)->tip_timer); | |
| 1566 | GTK_IMHTML(imhtml)->tip_timer = 0; | |
| 1567 | } | |
| 8061 | 1568 | if (GTK_IMHTML(imhtml)->editable) |
| 1569 | gdk_window_set_cursor(event_button->window, GTK_IMHTML(imhtml)->text_cursor); | |
| 1570 | else | |
| 1571 | gdk_window_set_cursor(event_button->window, GTK_IMHTML(imhtml)->arrow_cursor); | |
| 4417 | 1572 | menu = gtk_menu_new(); |
| 8677 | 1573 | g_object_set_data_full(G_OBJECT(menu), "x-imhtml-url-data", tempdata, url_data_destroy); |
| 4745 | 1574 | |
| 4417 | 1575 | /* buttons and such */ |
| 1576 | ||
| 8677 | 1577 | if (!strncmp(tempdata->url, "mailto:", 7)) |
|
7140
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1578 | { |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1579 | /* Copy E-Mail Address */ |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1580 | img = gtk_image_new_from_stock(GTK_STOCK_COPY, |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1581 | GTK_ICON_SIZE_MENU); |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1582 | item = gtk_image_menu_item_new_with_mnemonic( |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1583 | _("_Copy E-Mail Address")); |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1584 | 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
|
1585 | g_signal_connect(G_OBJECT(item), "activate", |
| 8677 | 1586 | G_CALLBACK(url_copy), tempdata->url + 7); |
|
7140
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1587 | gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
|
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 | else |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1590 | { |
| 10936 | 1591 | /* Open Link in Browser */ |
| 1592 | img = gtk_image_new_from_stock(GTK_STOCK_JUMP_TO, | |
| 1593 | GTK_ICON_SIZE_MENU); | |
| 1594 | item = gtk_image_menu_item_new_with_mnemonic( | |
| 1595 | _("_Open Link in Browser")); | |
| 1596 | gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); | |
| 1597 | g_signal_connect(G_OBJECT(item), "activate", | |
| 1598 | G_CALLBACK(url_open), tempdata); | |
| 1599 | gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
| 1600 | ||
|
7140
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1601 | /* Copy Link Location */ |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1602 | img = gtk_image_new_from_stock(GTK_STOCK_COPY, |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1603 | GTK_ICON_SIZE_MENU); |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1604 | item = gtk_image_menu_item_new_with_mnemonic( |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1605 | _("_Copy Link Location")); |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1606 | 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
|
1607 | g_signal_connect(G_OBJECT(item), "activate", |
| 8677 | 1608 | G_CALLBACK(url_copy), tempdata->url); |
|
7140
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1609 | gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1610 | } |
|
2670fa7da352
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1611 | |
|
4756
ee19a87a495f
[gaim-migrate @ 5073]
Mark Doliner <markdoliner@pidgin.im>
parents:
4745
diff
changeset
|
1612 | |
| 4417 | 1613 | gtk_widget_show_all(menu); |
|
4756
ee19a87a495f
[gaim-migrate @ 5073]
Mark Doliner <markdoliner@pidgin.im>
parents:
4745
diff
changeset
|
1614 | gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, |
|
ee19a87a495f
[gaim-migrate @ 5073]
Mark Doliner <markdoliner@pidgin.im>
parents:
4745
diff
changeset
|
1615 | event_button->button, event_button->time); |
| 4745 | 1616 | |
| 4417 | 1617 | return TRUE; |
| 1618 | } | |
| 1428 | 1619 | } |
| 4417 | 1620 | if(event->type == GDK_BUTTON_PRESS && event_button->button == 3) |
| 1621 | return TRUE; /* Clicking the right mouse button on a link shouldn't | |
| 1622 | be caught by the regular GtkTextView menu */ | |
| 1623 | else | |
| 1624 | return FALSE; /* Let clicks go through if we didn't catch anything */ | |
| 1428 | 1625 | } |
| 1626 | ||
| 9300 | 1627 | static gboolean |
| 1628 | gtk_text_view_drag_motion (GtkWidget *widget, | |
| 1629 | GdkDragContext *context, | |
| 1630 | gint x, | |
| 1631 | gint y, | |
| 1632 | guint time) | |
| 1633 | { | |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
1634 | GdkDragAction suggested_action = 0; |
| 9300 | 1635 | |
|
10145
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1636 | 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
|
1637 | /* can't accept any of the offered targets */ |
| 9300 | 1638 | } else { |
| 1639 | GtkWidget *source_widget; | |
| 1640 | suggested_action = context->suggested_action; | |
| 1641 | source_widget = gtk_drag_get_source_widget (context); | |
| 1642 | if (source_widget == widget) { | |
| 1643 | /* Default to MOVE, unless the user has | |
| 1644 | * pressed ctrl or alt to affect available actions | |
| 1645 | */ | |
| 1646 | if ((context->actions & GDK_ACTION_MOVE) != 0) | |
| 1647 | suggested_action = GDK_ACTION_MOVE; | |
| 1648 | } | |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
1649 | } |
|
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
1650 | |
|
10145
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1651 | gdk_drag_status (context, suggested_action, time); |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
1652 | |
| 9300 | 1653 | /* TRUE return means don't propagate the drag motion to parent |
| 1654 | * widgets that may also be drop sites. | |
| 1655 | */ | |
| 1656 | return TRUE; | |
| 1657 | } | |
| 1658 | ||
| 1659 | static void | |
| 1660 | gtk_imhtml_link_drop_cb(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer user_data) | |
| 1661 | { | |
| 1662 | GdkAtom target = gtk_drag_dest_find_target (widget, context, NULL); | |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
1663 | |
| 9300 | 1664 | if (target != GDK_NONE) |
| 1665 | gtk_drag_get_data (widget, context, target, time); | |
| 1666 | else | |
| 1667 | gtk_drag_finish (context, FALSE, FALSE, time); | |
| 1668 | ||
| 1669 | return; | |
| 1670 | } | |
| 1671 | ||
| 8091 | 1672 | static void |
| 1673 | 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
|
1674 | GtkSelectionData *sd, guint info, guint t, GtkIMHtml *imhtml) |
| 8091 | 1675 | { |
| 9300 | 1676 | gchar **links; |
| 1677 | gchar *link; | |
|
11143
f606fb334190
[gaim-migrate @ 13207]
Mark Doliner <markdoliner@pidgin.im>
parents:
11069
diff
changeset
|
1678 | char *text = (char *)sd->data; |
| 9300 | 1679 | GtkTextMark *mark = gtk_text_buffer_get_insert(imhtml->text_buffer); |
| 1680 | GtkTextIter iter; | |
|
10782
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1681 | gint i = 0; |
| 9300 | 1682 | |
| 1683 | gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); | |
| 1684 | ||
| 8091 | 1685 | if(gtk_imhtml_get_editable(imhtml) && sd->data){ |
| 9300 | 1686 | switch (info) { |
|
10145
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1687 | case GTK_IMHTML_DRAG_URL: |
|
11143
f606fb334190
[gaim-migrate @ 13207]
Mark Doliner <markdoliner@pidgin.im>
parents:
11069
diff
changeset
|
1688 | /* TODO: Is it really ok to change sd->data...? */ |
| 15884 | 1689 | purple_str_strip_char((char *)sd->data, '\r'); |
|
11143
f606fb334190
[gaim-migrate @ 13207]
Mark Doliner <markdoliner@pidgin.im>
parents:
11069
diff
changeset
|
1690 | |
|
f606fb334190
[gaim-migrate @ 13207]
Mark Doliner <markdoliner@pidgin.im>
parents:
11069
diff
changeset
|
1691 | links = g_strsplit((char *)sd->data, "\n", 0); |
|
10782
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1692 | while((link = links[i]) != NULL){ |
| 15884 | 1693 | if(purple_str_has_prefix(link, "http://") || |
| 1694 | purple_str_has_prefix(link, "https://") || | |
| 1695 | purple_str_has_prefix(link, "ftp://")) | |
|
10782
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1696 | { |
|
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1697 | gchar *label; |
|
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1698 | |
|
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1699 | if(links[i + 1]) |
|
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1700 | i++; |
|
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1701 | |
|
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1702 | label = links[i]; |
|
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1703 | |
|
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1704 | gtk_imhtml_insert_link(imhtml, mark, link, label); |
| 9300 | 1705 | } else if (link=='\0') { |
| 1706 | /* Ignore blank lines */ | |
| 1707 | } else { | |
| 1708 | /* 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
|
1709 | /* ... don't pretend we handled it if we didn't */ |
|
7d7f8cfa2b4f
[gaim-migrate @ 11556]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
10297
diff
changeset
|
1710 | gtk_drag_finish(dc, FALSE, FALSE, t); |
|
10782
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1711 | g_strfreev(links); |
|
10345
7d7f8cfa2b4f
[gaim-migrate @ 11556]
Felipe Contreras <felipe.contreras@gmail.com>
parents:
10297
diff
changeset
|
1712 | return; |
| 9300 | 1713 | } |
|
10782
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1714 | |
|
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1715 | i++; |
| 8091 | 1716 | } |
|
10782
18cc41076f4e
[gaim-migrate @ 12410]
Luke Schierer <lschiere@pidgin.im>
parents:
10777
diff
changeset
|
1717 | g_strfreev(links); |
| 9300 | 1718 | break; |
|
10145
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1719 | case GTK_IMHTML_DRAG_HTML: |
|
10243
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1720 | { |
|
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1721 | char *utf8 = NULL; |
|
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1722 | /* 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
|
1723 | * as explained by this comment in gtkhtml: |
|
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1724 | * |
|
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1725 | * 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
|
1726 | * mozilla/netscape alway use ucs2 for text/html |
|
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1727 | * 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
|
1728 | * 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
|
1729 | * |
|
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1730 | * See also the comment on text/html here: |
|
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1731 | * 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
|
1732 | */ |
|
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1733 | 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
|
1734 | utf8 = ucs2_to_utf8_with_bom_check(text, sd->length); |
|
10243
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1735 | |
|
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1736 | if (!utf8) { |
| 15884 | 1737 | purple_debug_warning("gtkimhtml", "g_convert from UCS-2 failed in drag_rcv_cb\n"); |
| 9300 | 1738 | return; |
| 1739 | } | |
|
10243
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1740 | } else if (!(*text) || !g_utf8_validate(text, -1, NULL)) { |
| 15884 | 1741 | purple_debug_warning("gtkimhtml", "empty string or invalid UTF-8 in drag_rcv_cb\n"); |
| 9300 | 1742 | return; |
| 1743 | } | |
|
10243
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1744 | |
|
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1745 | 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
|
1746 | g_free(utf8); |
| 9300 | 1747 | break; |
|
10243
6d75b29afc71
[gaim-migrate @ 11383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10217
diff
changeset
|
1748 | } |
|
10145
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1749 | case GTK_IMHTML_DRAG_TEXT: |
|
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1750 | 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"); |
|
10145
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1752 | return; |
|
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1753 | } else { |
|
10732
5e314ab498bf
[gaim-migrate @ 12334]
Richard Laager <rlaager@pidgin.im>
parents:
10699
diff
changeset
|
1754 | char *tmp = g_markup_escape_text(text, -1); |
|
10145
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1755 | gtk_imhtml_insert_html_at_iter(imhtml, tmp, 0, &iter); |
|
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1756 | g_free(tmp); |
|
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1757 | } |
|
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1758 | break; |
| 9300 | 1759 | default: |
|
10145
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1760 | gtk_drag_finish(dc, FALSE, FALSE, t); |
|
f1405f65ff41
[gaim-migrate @ 11218]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10110
diff
changeset
|
1761 | return; |
| 8091 | 1762 | } |
| 1763 | gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t); | |
| 1764 | } else { | |
| 1765 | gtk_drag_finish(dc, FALSE, FALSE, t); | |
| 1766 | } | |
| 1767 | } | |
| 1768 | ||
| 4298 | 1769 | /* this isn't used yet |
| 9300 | 1770 | static void gtk_smiley_tree_remove (GtkSmileyTree *tree, |
| 4263 | 1771 | GtkIMHtmlSmiley *smiley) |
| 4032 | 1772 | { |
| 1773 | GtkSmileyTree *t = tree; | |
| 4263 | 1774 | const gchar *x = smiley->smile; |
| 4032 | 1775 | gint len = 0; |
| 1776 | ||
| 1777 | while (*x) { | |
| 1778 | gchar *pos; | |
| 1779 | ||
| 1780 | if (!t->values) | |
| 1781 | return; | |
| 1782 | ||
| 1783 | pos = strchr (t->values->str, *x); | |
| 1784 | if (pos) | |
| 1785 | t = t->children [(int) pos - (int) t->values->str]; | |
| 1786 | else | |
| 1787 | return; | |
| 1788 | ||
| 1789 | x++; len++; | |
| 1790 | } | |
| 1791 | ||
| 4141 | 1792 | if (t->image) { |
| 4032 | 1793 | t->image = NULL; |
| 4141 | 1794 | } |
| 4032 | 1795 | } |
| 4298 | 1796 | */ |
| 1797 | ||
| 4032 | 1798 | |
| 1799 | static gint | |
| 1800 | gtk_smiley_tree_lookup (GtkSmileyTree *tree, | |
| 1801 | const gchar *text) | |
| 1802 | { | |
| 1803 | GtkSmileyTree *t = tree; | |
| 1804 | const gchar *x = text; | |
| 1805 | gint len = 0; | |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
1806 | const gchar *amp; |
| 8505 | 1807 | gint alen; |
| 4032 | 1808 | |
| 1809 | while (*x) { | |
| 1810 | gchar *pos; | |
| 1811 | ||
| 1812 | if (!t->values) | |
| 1813 | break; | |
| 1814 | ||
| 16144 | 1815 | if(*x == '&' && (amp = purple_markup_unescape_entity(x, &alen))) { |
|
10865
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1816 | gboolean matched = TRUE; |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1817 | /* Make sure all chars of the unescaped value match */ |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1818 | while (*(amp + 1)) { |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1819 | pos = strchr (t->values->str, *amp); |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1820 | if (pos) |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1821 | 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
|
1822 | else { |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1823 | matched = FALSE; |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1824 | break; |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1825 | } |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1826 | amp++; |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1827 | } |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1828 | if (!matched) |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1829 | break; |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1830 | |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1831 | pos = strchr (t->values->str, *amp); |
| 8505 | 1832 | } |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
1833 | else if (*x == '<') /* Because we're all WYSIWYG now, a '<' |
| 9636 | 1834 | * char should only appear as the start of a tag. Perhaps a safer (but costlier) |
| 1835 | * check would be to call gtk_imhtml_is_tag on it */ | |
| 10600 | 1836 | break; |
|
10865
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1837 | else { |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1838 | alen = 1; |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1839 | pos = strchr (t->values->str, *x); |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1840 | } |
| 8505 | 1841 | |
| 4032 | 1842 | if (pos) |
| 7371 | 1843 | t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)]; |
| 4032 | 1844 | else |
| 1845 | break; | |
| 1846 | ||
|
10865
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1847 | x += alen; |
|
f5bb66be81a0
[gaim-migrate @ 12549]
Daniel Atallah <datallah@pidgin.im>
parents:
10858
diff
changeset
|
1848 | len += alen; |
| 4032 | 1849 | } |
| 1850 | ||
| 1851 | if (t->image) | |
| 1852 | return len; | |
| 1853 | ||
| 1854 | return 0; | |
| 1855 | } | |
| 1856 | ||
| 1857 | void | |
| 4263 | 1858 | gtk_imhtml_associate_smiley (GtkIMHtml *imhtml, |
|
10537
9ece7671fa62
[gaim-migrate @ 11890]
Mark Doliner <markdoliner@pidgin.im>
parents:
10526
diff
changeset
|
1859 | const gchar *sml, |
| 4263 | 1860 | GtkIMHtmlSmiley *smiley) |
| 4032 | 1861 | { |
| 1862 | GtkSmileyTree *tree; | |
| 1863 | g_return_if_fail (imhtml != NULL); | |
| 1864 | g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 7371 | 1865 | |
| 4032 | 1866 | if (sml == NULL) |
| 1867 | tree = imhtml->default_smilies; | |
|
12833
1f461f275b90
[gaim-migrate @ 15181]
Richard Laager <rlaager@pidgin.im>
parents:
12796
diff
changeset
|
1868 | else if (!(tree = g_hash_table_lookup(imhtml->smiley_data, sml))) { |
| 4032 | 1869 | tree = gtk_smiley_tree_new(); |
| 4892 | 1870 | g_hash_table_insert(imhtml->smiley_data, g_strdup(sml), tree); |
| 4032 | 1871 | } |
| 1872 | ||
| 12335 | 1873 | smiley->imhtml = imhtml; |
| 1874 | ||
| 4263 | 1875 | gtk_smiley_tree_insert (tree, smiley); |
| 4032 | 1876 | } |
| 1877 | ||
| 1878 | static gboolean | |
| 1879 | gtk_imhtml_is_smiley (GtkIMHtml *imhtml, | |
| 1880 | GSList *fonts, | |
| 1881 | const gchar *text, | |
| 1882 | gint *len) | |
| 1883 | { | |
| 1884 | GtkSmileyTree *tree; | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
1885 | GtkIMHtmlFontDetail *font; |
| 4032 | 1886 | char *sml = NULL; |
| 1887 | ||
| 1888 | if (fonts) { | |
| 1889 | font = fonts->data; | |
| 1890 | sml = font->sml; | |
| 1891 | } | |
| 1892 | ||
| 9029 | 1893 | if (!sml) |
| 1894 | sml = imhtml->protocol_name; | |
| 1895 | ||
| 1896 | if (!sml || !(tree = g_hash_table_lookup(imhtml->smiley_data, sml))) | |
| 4032 | 1897 | tree = imhtml->default_smilies; |
| 9029 | 1898 | |
| 4032 | 1899 | if (tree == NULL) |
| 1900 | return FALSE; | |
| 7371 | 1901 | |
| 8505 | 1902 | *len = gtk_smiley_tree_lookup (tree, text); |
| 4032 | 1903 | return (*len > 0); |
| 1904 | } | |
| 1905 | ||
| 10526 | 1906 | GtkIMHtmlSmiley * |
| 1907 | gtk_imhtml_smiley_get(GtkIMHtml *imhtml, | |
| 1908 | const gchar *sml, | |
| 1909 | const gchar *text) | |
| 4032 | 1910 | { |
| 1911 | GtkSmileyTree *t; | |
| 1912 | const gchar *x = text; | |
| 1913 | if (sml == NULL) | |
| 1914 | t = imhtml->default_smilies; | |
| 7371 | 1915 | else |
| 4032 | 1916 | t = g_hash_table_lookup(imhtml->smiley_data, sml); |
| 7371 | 1917 | |
| 4032 | 1918 | |
| 1919 | if (t == NULL) | |
| 10526 | 1920 | return sml ? gtk_imhtml_smiley_get(imhtml, NULL, text) : NULL; |
| 4032 | 1921 | |
| 1922 | while (*x) { | |
| 1923 | gchar *pos; | |
| 1924 | ||
| 1925 | if (!t->values) { | |
| 10526 | 1926 | return sml ? gtk_imhtml_smiley_get(imhtml, NULL, text) : NULL; |
| 4032 | 1927 | } |
| 7371 | 1928 | |
| 4032 | 1929 | pos = strchr (t->values->str, *x); |
| 1930 | if (pos) { | |
| 7371 | 1931 | t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)]; |
| 4032 | 1932 | } else { |
| 10526 | 1933 | return sml ? gtk_imhtml_smiley_get(imhtml, NULL, text) : NULL; |
| 4032 | 1934 | } |
| 1935 | x++; | |
| 1936 | } | |
| 1937 | ||
| 10526 | 1938 | return t->image; |
| 1939 | } | |
| 1940 | ||
|
11677
89c2ab8d2ebf
[gaim-migrate @ 13963]
Mark Doliner <markdoliner@pidgin.im>
parents:
11586
diff
changeset
|
1941 | 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
|
1942 | gtk_smiley_get_image(GtkIMHtmlSmiley *smiley) |
| 10526 | 1943 | { |
| 1944 | if (!smiley->icon && smiley->file) { | |
| 1945 | smiley->icon = gdk_pixbuf_animation_new_from_file(smiley->file, NULL); | |
| 1946 | } else if (!smiley->icon && smiley->loader) { | |
| 1947 | smiley->icon = gdk_pixbuf_loader_get_animation(smiley->loader); | |
| 1948 | if (smiley->icon) | |
| 1949 | g_object_ref(G_OBJECT(smiley->icon)); | |
| 1950 | } | |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
1951 | |
| 10526 | 1952 | return smiley->icon; |
| 4032 | 1953 | } |
| 8890 | 1954 | |
|
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
|
1955 | 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
|
1956 | 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
|
1957 | 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
|
1958 | 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
|
1959 | { |
|
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
|
1960 | 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
|
1961 | |
|
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
|
1962 | 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
|
1963 | |
|
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
|
1964 | 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
|
1965 | 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
|
1966 | |
|
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 | 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
|
1968 | } |
|
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 | |
| 4793 | 1970 | #define VALID_TAG(x) if (!g_ascii_strncasecmp (string, x ">", strlen (x ">"))) { \ |
| 3922 | 1971 | *tag = g_strndup (string, strlen (x)); \ |
| 1972 | *len = strlen (x) + 1; \ | |
| 1973 | return TRUE; \ | |
| 1974 | } \ | |
| 1975 | (*type)++ | |
| 1428 | 1976 | |
| 4793 | 1977 | #define VALID_OPT_TAG(x) if (!g_ascii_strncasecmp (string, x " ", strlen (x " "))) { \ |
| 3922 | 1978 | const gchar *c = string + strlen (x " "); \ |
| 1979 | gchar e = '"'; \ | |
| 1980 | gboolean quote = FALSE; \ | |
| 1981 | while (*c) { \ | |
| 1982 | if (*c == '"' || *c == '\'') { \ | |
| 1983 | if (quote && (*c == e)) \ | |
| 1984 | quote = !quote; \ | |
| 1985 | else if (!quote) { \ | |
| 1986 | quote = !quote; \ | |
| 1987 | e = *c; \ | |
| 1988 | } \ | |
| 1989 | } else if (!quote && (*c == '>')) \ | |
| 1990 | break; \ | |
| 1991 | c++; \ | |
| 1992 | } \ | |
| 1993 | if (*c) { \ | |
| 1994 | *tag = g_strndup (string, c - string); \ | |
| 1995 | *len = c - string + 1; \ | |
| 1996 | return TRUE; \ | |
| 1997 | } \ | |
| 1998 | } \ | |
| 1999 | (*type)++ | |
| 1428 | 2000 | |
| 2001 | ||
|
1472
ce83d12b7df9
[gaim-migrate @ 1482]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1463
diff
changeset
|
2002 | static gboolean |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2003 | gtk_imhtml_is_tag (const gchar *string, |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2004 | gchar **tag, |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2005 | gint *len, |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2006 | gint *type) |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2007 | { |
| 8061 | 2008 | char *close; |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2009 | *type = 1; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2010 | |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2011 | |
| 8061 | 2012 | if (!(close = strchr (string, '>'))) |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2013 | return FALSE; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2014 | |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2015 | VALID_TAG ("B"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2016 | VALID_TAG ("BOLD"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2017 | VALID_TAG ("/B"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2018 | VALID_TAG ("/BOLD"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2019 | VALID_TAG ("I"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2020 | VALID_TAG ("ITALIC"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2021 | VALID_TAG ("/I"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2022 | VALID_TAG ("/ITALIC"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2023 | VALID_TAG ("U"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2024 | VALID_TAG ("UNDERLINE"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2025 | VALID_TAG ("/U"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2026 | VALID_TAG ("/UNDERLINE"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2027 | VALID_TAG ("S"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2028 | VALID_TAG ("STRIKE"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2029 | VALID_TAG ("/S"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2030 | VALID_TAG ("/STRIKE"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2031 | VALID_TAG ("SUB"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2032 | VALID_TAG ("/SUB"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2033 | VALID_TAG ("SUP"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2034 | VALID_TAG ("/SUP"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2035 | VALID_TAG ("PRE"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2036 | VALID_TAG ("/PRE"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2037 | VALID_TAG ("TITLE"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2038 | VALID_TAG ("/TITLE"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2039 | VALID_TAG ("BR"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2040 | VALID_TAG ("HR"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2041 | VALID_TAG ("/FONT"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2042 | VALID_TAG ("/A"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2043 | VALID_TAG ("P"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2044 | VALID_TAG ("/P"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2045 | VALID_TAG ("H3"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2046 | VALID_TAG ("/H3"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2047 | VALID_TAG ("HTML"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2048 | VALID_TAG ("/HTML"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2049 | VALID_TAG ("BODY"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2050 | VALID_TAG ("/BODY"); |
|
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 ("HEAD"); |
| 2993 | 2053 | VALID_TAG ("/HEAD"); |
| 2054 | VALID_TAG ("BINARY"); | |
| 2055 | VALID_TAG ("/BINARY"); | |
| 5093 | 2056 | |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2057 | VALID_OPT_TAG ("HR"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2058 | VALID_OPT_TAG ("FONT"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2059 | VALID_OPT_TAG ("BODY"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2060 | VALID_OPT_TAG ("A"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2061 | VALID_OPT_TAG ("IMG"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2062 | VALID_OPT_TAG ("P"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2063 | VALID_OPT_TAG ("H3"); |
| 5093 | 2064 | VALID_OPT_TAG ("HTML"); |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2065 | |
| 5101 | 2066 | VALID_TAG ("CITE"); |
| 2067 | VALID_TAG ("/CITE"); | |
| 2068 | VALID_TAG ("EM"); | |
| 2069 | VALID_TAG ("/EM"); | |
| 2070 | VALID_TAG ("STRONG"); | |
| 2071 | VALID_TAG ("/STRONG"); | |
| 2072 | ||
| 5104 | 2073 | VALID_OPT_TAG ("SPAN"); |
| 2074 | VALID_TAG ("/SPAN"); | |
| 5174 | 2075 | VALID_TAG ("BR/"); /* hack until gtkimhtml handles things better */ |
|
6982
12f08de92674
[gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
6882
diff
changeset
|
2076 | VALID_TAG ("IMG"); |
| 8026 | 2077 | VALID_TAG("SPAN"); |
| 8061 | 2078 | VALID_OPT_TAG("BR"); |
| 7988 | 2079 | |
| 4793 | 2080 | if (!g_ascii_strncasecmp(string, "!--", strlen ("!--"))) { |
|
2954
fc07d855731d
[gaim-migrate @ 2967]
Christian Hammond <chipx86@chipx86.com>
parents:
2898
diff
changeset
|
2081 | gchar *e = strstr (string + strlen("!--"), "-->"); |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2082 | if (e) { |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2083 | *len = e - string + strlen ("-->"); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2084 | *tag = g_strndup (string + strlen ("!--"), *len - strlen ("!---->")); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2085 | return TRUE; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2086 | } |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2087 | } |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2088 | |
| 8061 | 2089 | *type = -1; |
| 2090 | *len = close - string + 1; | |
| 2091 | *tag = g_strndup(string, *len - 1); | |
| 2092 | return TRUE; | |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2093 | } |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2094 | |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2095 | static gchar* |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2096 | gtk_imhtml_get_html_opt (gchar *tag, |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2097 | const gchar *opt) |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2098 | { |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2099 | gchar *t = tag; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2100 | gchar *e, *a; |
| 5177 | 2101 | gchar *val; |
| 2102 | gint len; | |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2103 | const gchar *c; |
| 5177 | 2104 | GString *ret; |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2105 | |
| 4793 | 2106 | while (g_ascii_strncasecmp (t, opt, strlen (opt))) { |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2107 | gboolean quote = FALSE; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2108 | if (*t == '\0') break; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2109 | while (*t && !((*t == ' ') && !quote)) { |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2110 | if (*t == '\"') |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2111 | quote = ! quote; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2112 | t++; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2113 | } |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2114 | while (*t && (*t == ' ')) t++; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2115 | } |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2116 | |
| 4793 | 2117 | if (!g_ascii_strncasecmp (t, opt, strlen (opt))) { |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2118 | t += strlen (opt); |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2119 | } else { |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2120 | return NULL; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2121 | } |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2122 | |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2123 | if ((*t == '\"') || (*t == '\'')) { |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2124 | e = a = ++t; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2125 | while (*e && (*e != *(t - 1))) e++; |
| 2993 | 2126 | if (*e == '\0') { |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2127 | return NULL; |
| 5177 | 2128 | } else |
| 2129 | val = g_strndup(a, e - a); | |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2130 | } else { |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2131 | e = a = t; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2132 | while (*e && !isspace ((gint) *e)) e++; |
| 5177 | 2133 | val = g_strndup(a, e - a); |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2134 | } |
| 5177 | 2135 | |
| 2136 | ret = g_string_new(""); | |
| 2137 | e = val; | |
| 2138 | while(*e) { | |
| 16144 | 2139 | if((c = purple_markup_unescape_entity(e, &len))) { |
| 7280 | 2140 | ret = g_string_append(ret, c); |
| 5177 | 2141 | e += len; |
| 2142 | } else { | |
| 2143 | ret = g_string_append_c(ret, *e); | |
| 2144 | e++; | |
| 2145 | } | |
| 2146 | } | |
| 2147 | ||
| 2148 | g_free(val); | |
|
8568
66907b37ce85
[gaim-migrate @ 9316]
Mark Doliner <markdoliner@pidgin.im>
parents:
8566
diff
changeset
|
2149 | |
|
66907b37ce85
[gaim-migrate @ 9316]
Mark Doliner <markdoliner@pidgin.im>
parents:
8566
diff
changeset
|
2150 | return g_string_free(ret, FALSE); |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2151 | } |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2152 | |
| 8334 | 2153 | static const char *accepted_protocols[] = { |
| 2154 | "http://", | |
| 2155 | "https://", | |
| 2156 | "ftp://" | |
| 2157 | }; | |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
2158 | |
| 8334 | 2159 | static const int accepted_protocols_size = 3; |
| 2160 | ||
| 2161 | /* returns if the beginning of the text is a protocol. If it is the protocol, returns the length so | |
| 2162 | the caller knows how long the protocol string is. */ | |
|
12412
8abe3226695e
[gaim-migrate @ 14719]
Richard Laager <rlaager@pidgin.im>
parents:
12335
diff
changeset
|
2163 | static int gtk_imhtml_is_protocol(const char *text) |
| 8334 | 2164 | { |
| 2165 | gint i; | |
| 2166 | ||
| 2167 | for(i=0; i<accepted_protocols_size; i++){ | |
| 2168 | if( strncasecmp(text, accepted_protocols[i], strlen(accepted_protocols[i])) == 0 ){ | |
| 2169 | return strlen(accepted_protocols[i]); | |
| 2170 | } | |
| 2171 | } | |
| 2172 | return 0; | |
| 2173 | } | |
| 2174 | ||
| 8677 | 2175 | /* |
| 15884 | 2176 | <KingAnt> marv: The two IM image functions in oscar are purple_odc_send_im and purple_odc_incoming |
| 8677 | 2177 | |
| 2178 | ||
| 2179 | [19:58] <Robot101> marv: images go into the imgstore, a refcounted... well.. hash. :) | |
| 2180 | [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
|
2181 | [19:59] Ro0tSiEgE robert42 RobFlynn Robot101 ross22 roz |
| 15884 | 2182 | [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 | 2183 | [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? |
| 2184 | [20:00] <KingAnt> marv: Right | |
| 2185 | [20:00] <marv> alright | |
| 2186 | ||
| 2187 | Here's my plan with IMImages. make gtk_imhtml_[append|insert]_text_with_images instead just | |
| 2188 | gtkimhtml_[append|insert]_text (hrm maybe it should be called html instead of text), add a | |
| 15884 | 2189 | function for purple to register for look up images, i.e. gtk_imhtml_set_get_img_fnc, so that |
| 8677 | 2190 | images can be looked up like that, instead of passing a GSList of them. |
| 2191 | */ | |
| 2192 | ||
| 2193 | void gtk_imhtml_append_text_with_images (GtkIMHtml *imhtml, | |
| 2194 | const gchar *text, | |
| 2195 | GtkIMHtmlOptions options, | |
| 2196 | GSList *unused) | |
| 1428 | 2197 | { |
| 8677 | 2198 | GtkTextIter iter, ins, sel; |
| 2199 | GdkRectangle rect; | |
| 2200 | int y, height, ins_offset = 0, sel_offset = 0; | |
| 2201 | gboolean fixins = FALSE, fixsel = FALSE; | |
| 2202 | ||
| 2203 | g_return_if_fail (imhtml != NULL); | |
| 2204 | g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 2205 | g_return_if_fail (text != NULL); | |
| 2206 | ||
| 2207 | ||
| 2208 | gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); | |
| 2209 | gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &ins, gtk_text_buffer_get_insert(imhtml->text_buffer)); | |
| 2210 | if (gtk_text_iter_equal(&iter, &ins) && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) { | |
| 2211 | fixins = TRUE; | |
| 2212 | ins_offset = gtk_text_iter_get_offset(&ins); | |
| 2213 | } | |
| 2214 | ||
| 2215 | gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &sel, gtk_text_buffer_get_selection_bound(imhtml->text_buffer)); | |
| 2216 | if (gtk_text_iter_equal(&iter, &sel) && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) { | |
| 2217 | fixsel = TRUE; | |
| 2218 | sel_offset = gtk_text_iter_get_offset(&sel); | |
| 2219 | } | |
| 2220 | ||
| 2221 | gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); | |
| 2222 | gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(imhtml), &iter, &y, &height); | |
| 2223 | ||
| 2224 | ||
| 2225 | if(((y + height) - (rect.y + rect.height)) > height | |
| 2226 | && gtk_text_buffer_get_char_count(imhtml->text_buffer)){ | |
| 2227 | options |= GTK_IMHTML_NO_SCROLL; | |
| 2228 | } | |
| 2229 | ||
| 2230 | gtk_imhtml_insert_html_at_iter(imhtml, text, options, &iter); | |
| 2231 | ||
| 2232 | if (fixins) { | |
| 2233 | gtk_text_buffer_get_iter_at_offset(imhtml->text_buffer, &ins, ins_offset); | |
| 2234 | gtk_text_buffer_move_mark(imhtml->text_buffer, gtk_text_buffer_get_insert(imhtml->text_buffer), &ins); | |
| 2235 | } | |
| 2236 | ||
| 2237 | if (fixsel) { | |
| 2238 | gtk_text_buffer_get_iter_at_offset(imhtml->text_buffer, &sel, sel_offset); | |
| 2239 | gtk_text_buffer_move_mark(imhtml->text_buffer, gtk_text_buffer_get_selection_bound(imhtml->text_buffer), &sel); | |
| 2240 | } | |
| 2241 | ||
| 2242 | if (!(options & GTK_IMHTML_NO_SCROLL)) { | |
| 12553 | 2243 | gtk_imhtml_scroll_to_end(imhtml, (options & GTK_IMHTML_USE_SMOOTHSCROLLING)); |
| 8677 | 2244 | } |
| 2245 | } | |
| 2246 | ||
| 11006 | 2247 | #define MAX_SCROLL_TIME 0.4 /* seconds */ |
| 2248 | #define SCROLL_DELAY 33 /* milliseconds */ | |
| 2249 | ||
| 2250 | /* | |
| 2251 | * Smoothly scroll a GtkIMHtml. | |
| 2252 | * | |
| 2253 | * @return TRUE if the window needs to be scrolled further, FALSE if we're at the bottom. | |
| 2254 | */ | |
|
10871
c0282a4f2250
[gaim-migrate @ 12558]
Mark Doliner <markdoliner@pidgin.im>
parents:
10865
diff
changeset
|
2255 | static gboolean scroll_cb(gpointer data) |
| 10798 | 2256 | { |
| 2257 | GtkIMHtml *imhtml = data; | |
| 2258 | GtkAdjustment *adj = GTK_TEXT_VIEW(imhtml)->vadjustment; | |
| 11006 | 2259 | gdouble max_val = adj->upper - adj->page_size; |
| 2260 | ||
| 2261 | g_return_val_if_fail(imhtml->scroll_time != NULL, FALSE); | |
| 2262 | ||
| 2263 | if (g_timer_elapsed(imhtml->scroll_time, NULL) > MAX_SCROLL_TIME) { | |
| 2264 | /* time's up. jump to the end and kill the timer */ | |
| 2265 | gtk_adjustment_set_value(adj, max_val); | |
| 10798 | 2266 | g_timer_destroy(imhtml->scroll_time); |
| 2267 | imhtml->scroll_time = NULL; | |
| 2268 | return FALSE; | |
| 11006 | 2269 | } |
| 2270 | ||
| 2271 | /* scroll by 1/3rd the remaining distance */ | |
| 2272 | gtk_adjustment_set_value(adj, gtk_adjustment_get_value(adj) + ((max_val - gtk_adjustment_get_value(adj)) / 3)); | |
| 2273 | return TRUE; | |
| 10798 | 2274 | } |
| 2275 | ||
| 12553 | 2276 | static gboolean smooth_scroll_idle_cb(gpointer data) |
| 10797 | 2277 | { |
| 10798 | 2278 | GtkIMHtml *imhtml = data; |
| 11006 | 2279 | imhtml->scroll_src = g_timeout_add(SCROLL_DELAY, scroll_cb, imhtml); |
| 10797 | 2280 | return FALSE; |
| 2281 | } | |
| 2282 | ||
| 12553 | 2283 | static gboolean scroll_idle_cb(gpointer data) |
| 2284 | { | |
| 2285 | GtkIMHtml *imhtml = data; | |
| 2286 | GtkAdjustment *adj = GTK_TEXT_VIEW(imhtml)->vadjustment; | |
| 2287 | if(adj) { | |
| 2288 | gtk_adjustment_set_value(adj, adj->upper - adj->page_size); | |
| 2289 | } | |
| 2290 | imhtml->scroll_src = 0; | |
| 2291 | return FALSE; | |
| 2292 | } | |
| 2293 | ||
| 2294 | void gtk_imhtml_scroll_to_end(GtkIMHtml *imhtml, gboolean smooth) | |
| 8729 | 2295 | { |
| 10798 | 2296 | if (imhtml->scroll_time) |
| 2297 | g_timer_destroy(imhtml->scroll_time); | |
| 2298 | if (imhtml->scroll_src) | |
| 2299 | g_source_remove(imhtml->scroll_src); | |
| 12553 | 2300 | if(smooth) { |
| 2301 | imhtml->scroll_time = g_timer_new(); | |
| 2302 | imhtml->scroll_src = g_idle_add_full(G_PRIORITY_LOW, smooth_scroll_idle_cb, imhtml, NULL); | |
| 2303 | } else { | |
| 2304 | imhtml->scroll_time = NULL; | |
| 2305 | imhtml->scroll_src = g_idle_add_full(G_PRIORITY_LOW, scroll_idle_cb, imhtml, NULL); | |
| 2306 | } | |
| 8729 | 2307 | } |
| 2308 | ||
| 8677 | 2309 | void gtk_imhtml_insert_html_at_iter(GtkIMHtml *imhtml, |
| 2310 | const gchar *text, | |
| 2311 | GtkIMHtmlOptions options, | |
| 2312 | GtkTextIter *iter) | |
| 2313 | { | |
| 8061 | 2314 | GdkRectangle rect; |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2315 | gint pos = 0; |
| 3922 | 2316 | gchar *ws; |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2317 | gchar *tag; |
| 3922 | 2318 | gchar *bg = NULL; |
|
6982
12f08de92674
[gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
6882
diff
changeset
|
2319 | gint len; |
| 4032 | 2320 | gint tlen, smilelen, wpos=0; |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2321 | gint type; |
| 3922 | 2322 | const gchar *c; |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2323 | const gchar *amp; |
| 8334 | 2324 | gint len_protocol; |
| 15379 | 2325 | |
| 1428 | 2326 | guint bold = 0, |
| 2327 | italics = 0, | |
| 2328 | underline = 0, | |
| 2329 | strike = 0, | |
| 2330 | sub = 0, | |
| 2331 | sup = 0, | |
|
1691
c8bd41036372
[gaim-migrate @ 1701]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1647
diff
changeset
|
2332 | title = 0, |
| 8061 | 2333 | pre = 0; |
| 1428 | 2334 | |
| 10217 | 2335 | gboolean br = FALSE; |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2336 | gboolean align_right = FALSE; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2337 | gboolean rtl_direction = FALSE; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2338 | gint align_line = 0; |
| 15420 | 2339 | |
| 3922 | 2340 | GSList *fonts = NULL; |
| 8506 | 2341 | GObject *object; |
| 8061 | 2342 | GtkIMHtmlScalable *scalable = NULL; |
| 8677 | 2343 | |
| 2344 | g_return_if_fail (imhtml != NULL); | |
| 2345 | g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 2346 | g_return_if_fail (text != NULL); | |
| 3922 | 2347 | c = text; |
|
6982
12f08de92674
[gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
6882
diff
changeset
|
2348 | len = strlen(text); |
| 3922 | 2349 | ws = g_malloc(len + 1); |
| 2350 | ws[0] = 0; | |
| 1428 | 2351 | |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2352 | while (pos < len) { |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2353 | if (*c == '<' && gtk_imhtml_is_tag (c + 1, &tag, &tlen, &type)) { |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2354 | c++; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2355 | pos++; |
| 8061 | 2356 | ws[wpos] = '\0'; |
| 10217 | 2357 | br = FALSE; |
| 8061 | 2358 | switch (type) |
| 3922 | 2359 | { |
| 2360 | case 1: /* B */ | |
| 2361 | case 2: /* BOLD */ | |
| 5101 | 2362 | case 54: /* STRONG */ |
|
11485
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2363 | if (!(options & GTK_IMHTML_NO_FORMATTING)) { |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2364 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2365 | |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2366 | if ((bold == 0) && (imhtml->format_functions & GTK_IMHTML_BOLD)) |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2367 | gtk_imhtml_toggle_bold(imhtml); |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2368 | bold++; |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2369 | ws[0] = '\0'; wpos = 0; |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2370 | } |
| 3922 | 2371 | break; |
| 2372 | case 3: /* /B */ | |
| 2373 | case 4: /* /BOLD */ | |
| 5101 | 2374 | case 55: /* /STRONG */ |
|
11485
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2375 | if (!(options & GTK_IMHTML_NO_FORMATTING)) { |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2376 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2377 | ws[0] = '\0'; wpos = 0; |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2378 | |
|
14010
a47143a57c82
[gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents:
13552
diff
changeset
|
2379 | if (bold) { |
|
11485
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2380 | bold--; |
|
14010
a47143a57c82
[gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents:
13552
diff
changeset
|
2381 | if ((bold == 0) && (imhtml->format_functions & GTK_IMHTML_BOLD) && !imhtml->wbfo) |
|
a47143a57c82
[gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents:
13552
diff
changeset
|
2382 | gtk_imhtml_toggle_bold(imhtml); |
|
a47143a57c82
[gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents:
13552
diff
changeset
|
2383 | } |
|
11485
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2384 | } |
| 3922 | 2385 | break; |
| 2386 | case 5: /* I */ | |
| 2387 | case 6: /* ITALIC */ | |
| 5101 | 2388 | case 52: /* EM */ |
|
11485
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2389 | if (!(options & GTK_IMHTML_NO_FORMATTING)) { |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2390 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2391 | ws[0] = '\0'; wpos = 0; |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2392 | if ((italics == 0) && (imhtml->format_functions & GTK_IMHTML_ITALIC)) |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2393 | gtk_imhtml_toggle_italic(imhtml); |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2394 | italics++; |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2395 | } |
| 3922 | 2396 | break; |
| 2397 | case 7: /* /I */ | |
| 2398 | case 8: /* /ITALIC */ | |
| 5101 | 2399 | case 53: /* /EM */ |
|
11485
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2400 | if (!(options & GTK_IMHTML_NO_FORMATTING)) { |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2401 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2402 | ws[0] = '\0'; wpos = 0; |
|
14010
a47143a57c82
[gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents:
13552
diff
changeset
|
2403 | if (italics) { |
|
11485
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2404 | italics--; |
|
14010
a47143a57c82
[gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents:
13552
diff
changeset
|
2405 | if ((italics == 0) && (imhtml->format_functions & GTK_IMHTML_ITALIC) && !imhtml->wbfo) |
|
a47143a57c82
[gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents:
13552
diff
changeset
|
2406 | gtk_imhtml_toggle_italic(imhtml); |
|
a47143a57c82
[gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents:
13552
diff
changeset
|
2407 | } |
|
11485
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2408 | } |
| 3922 | 2409 | break; |
| 2410 | case 9: /* U */ | |
| 2411 | case 10: /* UNDERLINE */ | |
|
11485
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2412 | if (!(options & GTK_IMHTML_NO_FORMATTING)) { |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2413 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2414 | ws[0] = '\0'; wpos = 0; |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2415 | if ((underline == 0) && (imhtml->format_functions & GTK_IMHTML_UNDERLINE)) |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2416 | gtk_imhtml_toggle_underline(imhtml); |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2417 | underline++; |
|
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2418 | } |
| 3922 | 2419 | break; |
| 2420 | case 11: /* /U */ | |
| 2421 | case 12: /* /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; |
|
14010
a47143a57c82
[gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents:
13552
diff
changeset
|
2425 | if (underline) { |
|
11485
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2426 | underline--; |
|
14010
a47143a57c82
[gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents:
13552
diff
changeset
|
2427 | if ((underline == 0) && (imhtml->format_functions & GTK_IMHTML_UNDERLINE) && !imhtml->wbfo) |
|
a47143a57c82
[gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents:
13552
diff
changeset
|
2428 | gtk_imhtml_toggle_underline(imhtml); |
|
a47143a57c82
[gaim-migrate @ 16489]
Gary Kramlich <grim@reaperworld.com>
parents:
13552
diff
changeset
|
2429 | } |
|
11485
fe334b13d1d0
[gaim-migrate @ 13727]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11385
diff
changeset
|
2430 | } |
| 3922 | 2431 | break; |
| 2432 | case 13: /* S */ | |
| 2433 | case 14: /* STRIKE */ | |
| 9924 | 2434 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 2435 | ws[0] = '\0'; wpos = 0; | |
| 2436 | if ((strike == 0) && (imhtml->format_functions & GTK_IMHTML_STRIKE)) | |
| 2437 | gtk_imhtml_toggle_strike(imhtml); | |
| 3922 | 2438 | strike++; |
| 2439 | break; | |
| 2440 | case 15: /* /S */ | |
| 2441 | case 16: /* /STRIKE */ | |
| 9924 | 2442 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 2443 | ws[0] = '\0'; wpos = 0; | |
| 3922 | 2444 | if (strike) |
| 2445 | strike--; | |
| 9924 | 2446 | if ((strike == 0) && (imhtml->format_functions & GTK_IMHTML_STRIKE) && !imhtml->wbfo) |
| 2447 | gtk_imhtml_toggle_strike(imhtml); | |
| 3922 | 2448 | break; |
| 2449 | case 17: /* SUB */ | |
| 8677 | 2450 | /* FIXME: reimpliment this */ |
| 3922 | 2451 | sub++; |
| 2452 | break; | |
| 2453 | case 18: /* /SUB */ | |
| 8677 | 2454 | /* FIXME: reimpliment this */ |
| 3922 | 2455 | if (sub) |
| 2456 | sub--; | |
| 2457 | break; | |
| 2458 | case 19: /* SUP */ | |
| 8677 | 2459 | /* FIXME: reimplement this */ |
| 3922 | 2460 | sup++; |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2461 | break; |
| 3922 | 2462 | case 20: /* /SUP */ |
| 8677 | 2463 | /* FIXME: reimplement this */ |
| 3922 | 2464 | if (sup) |
| 2465 | sup--; | |
| 2466 | break; | |
| 2467 | case 21: /* PRE */ | |
| 8677 | 2468 | /* FIXME: reimplement this */ |
| 3922 | 2469 | pre++; |
| 2470 | break; | |
| 2471 | case 22: /* /PRE */ | |
| 8677 | 2472 | /* FIXME: reimplement this */ |
| 3922 | 2473 | if (pre) |
| 2474 | pre--; | |
| 2475 | break; | |
| 2476 | case 23: /* TITLE */ | |
| 8677 | 2477 | /* FIXME: what was this supposed to do anyway? */ |
| 3922 | 2478 | title++; |
| 2479 | break; | |
| 2480 | case 24: /* /TITLE */ | |
| 8677 | 2481 | /* FIXME: make this undo whatever 23 was supposed to do */ |
| 3922 | 2482 | if (title) { |
| 2483 | if (options & GTK_IMHTML_NO_TITLE) { | |
| 2484 | wpos = 0; | |
| 2485 | ws [wpos] = '\0'; | |
| 2486 | } | |
| 2487 | title--; | |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2488 | } |
| 3922 | 2489 | break; |
| 2490 | case 25: /* BR */ | |
| 5174 | 2491 | case 58: /* BR/ */ |
| 8061 | 2492 | case 61: /* BR (opt) */ |
| 3922 | 2493 | ws[wpos] = '\n'; |
| 2494 | wpos++; | |
| 10217 | 2495 | br = TRUE; |
|
6982
12f08de92674
[gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
6882
diff
changeset
|
2496 | break; |
| 3922 | 2497 | case 26: /* HR */ |
| 2498 | case 42: /* HR (opt) */ | |
| 8726 | 2499 | { |
| 2500 | int minus; | |
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
2501 | struct scalable_data *sd = g_new(struct scalable_data, 1); |
| 8726 | 2502 | |
| 3922 | 2503 | ws[wpos++] = '\n'; |
| 8677 | 2504 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 2505 | ||
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
2506 | sd->scalable = scalable = gtk_imhtml_hr_new(); |
|
11233
28c0f184a2d4
[gaim-migrate @ 13373]
Daniel Atallah <datallah@pidgin.im>
parents:
11224
diff
changeset
|
2507 | sd->mark = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, iter, TRUE); |
| 8061 | 2508 | gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); |
| 8677 | 2509 | scalable->add_to(scalable, imhtml, iter); |
| 8726 | 2510 | minus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(imhtml)) + |
| 2511 | gtk_text_view_get_right_margin(GTK_TEXT_VIEW(imhtml)); | |
| 2512 | scalable->scale(scalable, rect.width - minus, rect.height); | |
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
2513 | imhtml->scalables = g_list_append(imhtml->scalables, sd); |
| 8061 | 2514 | ws[0] = '\0'; wpos = 0; |
| 7942 | 2515 | ws[wpos++] = '\n'; |
| 8061 | 2516 | |
| 3922 | 2517 | break; |
| 8726 | 2518 | } |
| 3922 | 2519 | case 27: /* /FONT */ |
| 8677 | 2520 | if (fonts && !imhtml->wbfo) { |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
2521 | GtkIMHtmlFontDetail *font = fonts->data; |
| 8677 | 2522 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 2523 | ws[0] = '\0'; wpos = 0; |
|
8177
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
2524 | /* NEW_BIT (NEW_TEXT_BIT); */ |
| 8677 | 2525 | |
| 8698 | 2526 | if (font->face && (imhtml->format_functions & GTK_IMHTML_FACE)) { |
| 8061 | 2527 | gtk_imhtml_toggle_fontface(imhtml, NULL); |
| 2528 | } | |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2529 | g_free (font->face); |
| 8698 | 2530 | if (font->fore && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) { |
| 8061 | 2531 | gtk_imhtml_toggle_forecolor(imhtml, NULL); |
| 2532 | } | |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2533 | g_free (font->fore); |
| 8698 | 2534 | if (font->back && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) { |
| 8061 | 2535 | gtk_imhtml_toggle_backcolor(imhtml, NULL); |
| 2536 | } | |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2537 | g_free (font->back); |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2538 | g_free (font->sml); |
| 8309 | 2539 | |
| 8698 | 2540 | if ((font->size != 3) && (imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) |
| 8309 | 2541 | gtk_imhtml_font_set_size(imhtml, 3); |
| 2542 | ||
| 10761 | 2543 | fonts = g_slist_remove (fonts, font); |
| 9245 | 2544 | g_free(font); |
| 2545 | ||
| 8309 | 2546 | if (fonts) { |
| 2547 | GtkIMHtmlFontDetail *font = fonts->data; | |
| 8677 | 2548 | |
| 8698 | 2549 | if (font->face && (imhtml->format_functions & GTK_IMHTML_FACE)) |
| 8309 | 2550 | gtk_imhtml_toggle_fontface(imhtml, font->face); |
| 8698 | 2551 | if (font->fore && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) |
| 8309 | 2552 | gtk_imhtml_toggle_forecolor(imhtml, font->fore); |
| 8698 | 2553 | if (font->back && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) |
| 8309 | 2554 | gtk_imhtml_toggle_backcolor(imhtml, font->back); |
| 8698 | 2555 | if ((font->size != 3) && (imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) |
| 8309 | 2556 | gtk_imhtml_font_set_size(imhtml, font->size); |
| 2557 | } | |
| 3922 | 2558 | } |
| 8309 | 2559 | break; |
| 3922 | 2560 | case 28: /* /A */ |
| 8677 | 2561 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 2562 | gtk_imhtml_toggle_link(imhtml, NULL); | |
| 2563 | ws[0] = '\0'; wpos = 0; | |
| 8061 | 2564 | break; |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2565 | |
| 3922 | 2566 | case 29: /* P */ |
| 2567 | case 30: /* /P */ | |
| 2568 | case 31: /* H3 */ | |
| 2569 | case 32: /* /H3 */ | |
| 2570 | case 33: /* HTML */ | |
| 2571 | case 34: /* /HTML */ | |
| 2572 | case 35: /* BODY */ | |
| 10776 | 2573 | break; |
| 3922 | 2574 | case 36: /* /BODY */ |
| 10786 | 2575 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 2576 | ws[0] = '\0'; wpos = 0; | |
| 10776 | 2577 | gtk_imhtml_toggle_background(imhtml, NULL); |
| 2578 | break; | |
| 3922 | 2579 | case 37: /* FONT */ |
| 2580 | case 38: /* HEAD */ | |
| 2581 | case 39: /* /HEAD */ | |
|
6982
12f08de92674
[gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
6882
diff
changeset
|
2582 | case 40: /* BINARY */ |
|
12f08de92674
[gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
6882
diff
changeset
|
2583 | case 41: /* /BINARY */ |
| 3922 | 2584 | break; |
| 2585 | case 43: /* FONT (opt) */ | |
| 2586 | { | |
| 4032 | 2587 | gchar *color, *back, *face, *size, *sml; |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
2588 | GtkIMHtmlFontDetail *font, *oldfont = NULL; |
| 3922 | 2589 | color = gtk_imhtml_get_html_opt (tag, "COLOR="); |
| 2590 | back = gtk_imhtml_get_html_opt (tag, "BACK="); | |
| 2591 | face = gtk_imhtml_get_html_opt (tag, "FACE="); | |
| 2592 | size = gtk_imhtml_get_html_opt (tag, "SIZE="); | |
| 4032 | 2593 | sml = gtk_imhtml_get_html_opt (tag, "SML="); |
| 2594 | if (!(color || back || face || size || sml)) | |
| 3922 | 2595 | break; |
| 8061 | 2596 | |
| 8677 | 2597 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 2598 | ws[0] = '\0'; wpos = 0; |
| 2599 | ||
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
2600 | font = g_new0 (GtkIMHtmlFontDetail, 1); |
| 3922 | 2601 | if (fonts) |
| 2602 | oldfont = fonts->data; | |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2603 | |
| 8677 | 2604 | if (color && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) { |
| 3922 | 2605 | font->fore = color; |
| 8061 | 2606 | gtk_imhtml_toggle_forecolor(imhtml, font->fore); |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2607 | } else |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2608 | g_free(color); |
| 8677 | 2609 | |
| 2610 | if (back && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) { | |
| 3922 | 2611 | font->back = back; |
| 8061 | 2612 | gtk_imhtml_toggle_backcolor(imhtml, font->back); |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2613 | } else |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2614 | g_free(back); |
| 8677 | 2615 | |
| 2616 | if (face && !(options & GTK_IMHTML_NO_FONTS) && (imhtml->format_functions & GTK_IMHTML_FACE)) { | |
| 3922 | 2617 | font->face = face; |
| 8061 | 2618 | gtk_imhtml_toggle_fontface(imhtml, font->face); |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2619 | } else |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2620 | g_free(face); |
| 4032 | 2621 | |
| 2622 | if (sml) | |
| 2623 | font->sml = sml; | |
| 2624 | else if (oldfont && oldfont->sml) | |
| 2625 | font->sml = g_strdup(oldfont->sml); | |
| 2626 | ||
| 8677 | 2627 | if (size && !(options & GTK_IMHTML_NO_SIZES) && (imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) { |
| 3922 | 2628 | if (*size == '+') { |
| 2629 | sscanf (size + 1, "%hd", &font->size); | |
| 2630 | font->size += 3; | |
| 2631 | } else if (*size == '-') { | |
| 2632 | sscanf (size + 1, "%hd", &font->size); | |
| 2633 | font->size = MAX (0, 3 - font->size); | |
| 2634 | } else if (isdigit (*size)) { | |
| 2635 | sscanf (size, "%hd", &font->size); | |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2636 | } |
|
6042
e329fe962c9a
[gaim-migrate @ 6492]
Mark Doliner <markdoliner@pidgin.im>
parents:
5967
diff
changeset
|
2637 | if (font->size > 100) |
|
e329fe962c9a
[gaim-migrate @ 6492]
Mark Doliner <markdoliner@pidgin.im>
parents:
5967
diff
changeset
|
2638 | font->size = 100; |
| 3922 | 2639 | } else if (oldfont) |
| 2640 | font->size = oldfont->size; | |
| 8309 | 2641 | else |
| 2642 | font->size = 3; | |
| 8698 | 2643 | if ((imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) |
| 2644 | gtk_imhtml_font_set_size(imhtml, font->size); | |
| 3922 | 2645 | g_free(size); |
| 2646 | fonts = g_slist_prepend (fonts, font); | |
| 2647 | } | |
| 2648 | break; | |
| 2649 | case 44: /* BODY (opt) */ | |
| 2650 | if (!(options & GTK_IMHTML_NO_COLOURS)) { | |
| 2651 | char *bgcolor = gtk_imhtml_get_html_opt (tag, "BGCOLOR="); | |
| 8677 | 2652 | if (bgcolor && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) { |
| 2653 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
| 8061 | 2654 | ws[0] = '\0'; wpos = 0; |
|
8177
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
2655 | /* NEW_BIT(NEW_TEXT_BIT); */ |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
2656 | g_free(bg); |
| 3922 | 2657 | bg = bgcolor; |
| 10776 | 2658 | gtk_imhtml_toggle_background(imhtml, bg); |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2659 | } else |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2660 | g_free(bgcolor); |
| 1428 | 2661 | } |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2662 | break; |
| 3922 | 2663 | case 45: /* A (opt) */ |
| 2664 | { | |
| 2665 | gchar *href = gtk_imhtml_get_html_opt (tag, "HREF="); | |
| 8677 | 2666 | if (href && (imhtml->format_functions & GTK_IMHTML_LINK)) { |
| 2667 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
| 8061 | 2668 | ws[0] = '\0'; wpos = 0; |
| 8677 | 2669 | gtk_imhtml_toggle_link(imhtml, href); |
| 3922 | 2670 | } |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
2671 | g_free(href); |
| 2993 | 2672 | } |
| 3922 | 2673 | break; |
| 4895 | 2674 | case 46: /* IMG (opt) */ |
|
6982
12f08de92674
[gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
6882
diff
changeset
|
2675 | case 59: /* IMG */ |
| 4895 | 2676 | { |
| 8962 | 2677 | const char *id; |
| 2678 | ||
| 2679 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
| 2680 | ws[0] = '\0'; wpos = 0; | |
| 4895 | 2681 | |
| 8677 | 2682 | if (!(imhtml->format_functions & GTK_IMHTML_IMAGE)) |
| 2683 | break; | |
| 2684 | ||
| 8962 | 2685 | id = gtk_imhtml_get_html_opt(tag, "ID="); |
| 9186 | 2686 | if (!id) |
| 2687 | break; | |
| 8962 | 2688 | gtk_imhtml_insert_image_at_iter(imhtml, atoi(id), iter); |
| 2689 | break; | |
| 4895 | 2690 | } |
| 3922 | 2691 | case 47: /* P (opt) */ |
| 2692 | case 48: /* H3 (opt) */ | |
| 5093 | 2693 | case 49: /* HTML (opt) */ |
| 5101 | 2694 | case 50: /* CITE */ |
| 2695 | case 51: /* /CITE */ | |
| 8026 | 2696 | case 56: /* SPAN (opt) */ |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2697 | /* Inline CSS Support - Douglas Thrift |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2698 | * |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2699 | * color |
| 8686 | 2700 | * background |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2701 | * font-family |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2702 | * font-size |
| 8686 | 2703 | * text-decoration: underline |
| 14395 | 2704 | * font-weight: bold |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2705 | * direction: rtl |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2706 | * text-align: right |
| 10483 | 2707 | * |
| 2708 | * TODO: | |
| 2709 | * background-color | |
| 2710 | * font-style | |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2711 | */ |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2712 | { |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2713 | gchar *style, *color, *background, *family, *size, *direction, *alignment; |
| 14395 | 2714 | gchar *textdec, *weight; |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2715 | GtkIMHtmlFontDetail *font, *oldfont = NULL; |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2716 | style = gtk_imhtml_get_html_opt (tag, "style="); |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2717 | |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2718 | if (!style) break; |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2719 | |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2720 | color = purple_markup_get_css_property (style, "color"); |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2721 | background = purple_markup_get_css_property (style, "background"); |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2722 | 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
|
2723 | 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
|
2724 | 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
|
2725 | 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
|
2726 | direction = purple_markup_get_css_property (style, "direction"); |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2727 | 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
|
2728 | |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2729 | |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2730 | if (!(color || family || size || background || textdec || weight || direction || alignment)) { |
| 8120 | 2731 | g_free(style); |
| 2732 | break; | |
| 2733 | } | |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2734 | |
| 8677 | 2735 | |
| 2736 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2737 | ws[0] = '\0'; wpos = 0; |
|
8177
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
2738 | /* NEW_BIT (NEW_TEXT_BIT); */ |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2739 | |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2740 | /* Bi-Directional text support */ |
| 16144 | 2741 | if (direction && (!strncasecmp(direction, "RTL", 3))) { |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2742 | rtl_direction = TRUE; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2743 | /* insert RLE character to set direction */ |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2744 | ws[wpos++] = 0xE2; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2745 | ws[wpos++] = 0x80; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2746 | ws[wpos++] = 0xAB; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2747 | ws[wpos] = '\0'; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2748 | 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
|
2749 | ws[0] = '\0'; wpos = 0; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2750 | } |
| 16144 | 2751 | g_free(direction); |
| 2752 | ||
| 2753 | if (alignment && (!strncasecmp(alignment, "RIGHT", 5))) { | |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2754 | align_right = TRUE; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2755 | align_line = gtk_text_iter_get_line(iter); |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2756 | } |
| 16144 | 2757 | g_free(alignment); |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
2758 | |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2759 | font = g_new0 (GtkIMHtmlFontDetail, 1); |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2760 | if (fonts) |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2761 | oldfont = fonts->data; |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2762 | |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2763 | 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
|
2764 | font->fore = color; |
| 8686 | 2765 | gtk_imhtml_toggle_forecolor(imhtml, font->fore); |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2766 | } else { |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2767 | if (oldfont && oldfont->fore) |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2768 | font->fore = g_strdup(oldfont->fore); |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2769 | g_free(color); |
| 8686 | 2770 | } |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2771 | |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2772 | if (background && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) { |
| 8686 | 2773 | font->back = background; |
| 2774 | gtk_imhtml_toggle_backcolor(imhtml, font->back); | |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2775 | } else { |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2776 | if (oldfont && oldfont->back) |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2777 | font->back = g_strdup(oldfont->back); |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2778 | g_free(background); |
| 8686 | 2779 | } |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2780 | |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2781 | 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
|
2782 | font->face = family; |
| 8686 | 2783 | gtk_imhtml_toggle_fontface(imhtml, font->face); |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2784 | } else { |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2785 | if (oldfont && oldfont->face) |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2786 | font->face = g_strdup(oldfont->face); |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2787 | g_free(family); |
| 8686 | 2788 | } |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2789 | if (font->face && (atoi(font->face) > 100)) { |
| 8677 | 2790 | /* WTF is this? */ |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
2791 | /* 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
|
2792 | * remember bad things happening if the font size was |
|
9696
9d62e1ec5977
[gaim-migrate @ 10555]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9636
diff
changeset
|
2793 | * 2 billion */ |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2794 | g_free(font->face); |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2795 | font->face = g_strdup("100"); |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2796 | } |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2797 | |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2798 | if (oldfont && oldfont->sml) |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2799 | font->sml = g_strdup(oldfont->sml); |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2800 | |
| 8677 | 2801 | if (size && !(options & GTK_IMHTML_NO_SIZES) && (imhtml->format_functions & (GTK_IMHTML_SHRINK|GTK_IMHTML_GROW))) { |
| 8686 | 2802 | if (g_ascii_strcasecmp(size, "xx-small") == 0) |
| 2803 | font->size = 1; | |
| 2804 | else if (g_ascii_strcasecmp(size, "smaller") == 0 | |
| 2805 | || g_ascii_strcasecmp(size, "x-small") == 0) | |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2806 | font->size = 2; |
| 8686 | 2807 | else if (g_ascii_strcasecmp(size, "larger") == 0 |
| 2808 | || g_ascii_strcasecmp(size, "medium") == 0) | |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2809 | font->size = 4; |
| 8686 | 2810 | else if (g_ascii_strcasecmp(size, "large") == 0) |
| 2811 | font->size = 5; | |
| 2812 | else if (g_ascii_strcasecmp(size, "x-large") == 0) | |
| 2813 | font->size = 6; | |
| 2814 | else if (g_ascii_strcasecmp(size, "xx-large") == 0) | |
| 2815 | font->size = 7; | |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2816 | else |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2817 | font->size = 3; |
| 8686 | 2818 | gtk_imhtml_font_set_size(imhtml, font->size); |
| 2819 | } | |
| 2820 | else if (oldfont) | |
| 2821 | { | |
| 2822 | font->size = oldfont->size; | |
| 2823 | } | |
| 2824 | ||
| 2825 | if (oldfont) | |
| 2826 | { | |
| 2827 | font->underline = oldfont->underline; | |
| 2828 | } | |
| 2829 | if (textdec && font->underline != 1 | |
| 9025 | 2830 | && 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
|
2831 | && (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
|
2832 | && !(options & GTK_IMHTML_NO_FORMATTING)) |
| 8686 | 2833 | { |
| 2834 | gtk_imhtml_toggle_underline(imhtml); | |
| 2835 | font->underline = 1; | |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2836 | } else |
|
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2837 | g_free(textdec); |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2838 | |
| 14395 | 2839 | if (oldfont) |
| 2840 | { | |
| 2841 | font->bold = oldfont->bold; | |
| 2842 | } | |
| 2843 | if (weight) | |
| 2844 | { | |
| 2845 | if(!g_ascii_strcasecmp(weight, "normal")) { | |
| 2846 | font->bold = 0; | |
| 2847 | } else if(!g_ascii_strcasecmp(weight, "bold")) { | |
| 2848 | font->bold = 1; | |
| 2849 | } else if(!g_ascii_strcasecmp(weight, "bolder")) { | |
| 2850 | font->bold++; | |
| 2851 | } else if(!g_ascii_strcasecmp(weight, "lighter")) { | |
| 2852 | if(font->bold > 0) | |
| 2853 | font->bold--; | |
| 2854 | } else { | |
| 2855 | int num = atoi(weight); | |
| 2856 | if(num >= 700) | |
| 2857 | font->bold = 1; | |
| 2858 | else | |
| 2859 | font->bold = 0; | |
| 2860 | } | |
|
17088
1ecea6e2fd97
Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17009
diff
changeset
|
2861 | if (((font->bold && oldfont && !oldfont->bold) || (oldfont && oldfont->bold && !font->bold) || (font->bold && !oldfont)) && !(options & GTK_IMHTML_NO_FORMATTING)) |
| 14395 | 2862 | { |
| 2863 | gtk_imhtml_toggle_bold(imhtml); | |
| 2864 | } | |
|
14821
c91127e2b784
[gaim-migrate @ 17516]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14741
diff
changeset
|
2865 | g_free(weight); |
| 14395 | 2866 | } |
| 2867 | ||
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2868 | g_free(style); |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2869 | g_free(size); |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2870 | fonts = g_slist_prepend (fonts, font); |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2871 | } |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2872 | break; |
| 5104 | 2873 | case 57: /* /SPAN */ |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2874 | /* Inline CSS Support - Douglas Thrift */ |
| 8677 | 2875 | if (fonts && !imhtml->wbfo) { |
| 8686 | 2876 | GtkIMHtmlFontDetail *oldfont = NULL; |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2877 | GtkIMHtmlFontDetail *font = fonts->data; |
| 8677 | 2878 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2879 | ws[0] = '\0'; wpos = 0; |
|
8177
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
2880 | /* NEW_BIT (NEW_TEXT_BIT); */ |
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2881 | fonts = g_slist_remove (fonts, font); |
| 8692 | 2882 | if (fonts) |
| 2883 | oldfont = fonts->data; | |
| 2884 | ||
| 2885 | if (!oldfont) { | |
| 2886 | 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
|
2887 | if (font->underline && !(options & GTK_IMHTML_NO_FORMATTING)) |
| 8692 | 2888 | 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
|
2889 | if (font->bold && !(options & GTK_IMHTML_NO_FORMATTING)) |
| 14395 | 2890 | 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
|
2891 | 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
|
2892 | 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
|
2893 | 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
|
2894 | 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
|
2895 | 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
|
2896 | gtk_imhtml_toggle_backcolor(imhtml, NULL); |
| 8686 | 2897 | } |
| 8692 | 2898 | else |
| 8686 | 2899 | { |
| 8692 | 2900 | |
|
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 ((font->size != oldfont->size) && !(options & GTK_IMHTML_NO_SIZES)) |
| 8692 | 2902 | gtk_imhtml_font_set_size(imhtml, oldfont->size); |
| 2903 | ||
|
17088
1ecea6e2fd97
Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17009
diff
changeset
|
2904 | if ((font->underline != oldfont->underline) && !(options & GTK_IMHTML_NO_FORMATTING)) |
| 8692 | 2905 | gtk_imhtml_toggle_underline(imhtml); |
| 2906 | ||
|
17088
1ecea6e2fd97
Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17009
diff
changeset
|
2907 | if (((font->bold && !oldfont->bold) || (oldfont->bold && !font->bold)) && !(options & GTK_IMHTML_NO_FORMATTING)) |
| 14395 | 2908 | gtk_imhtml_toggle_bold(imhtml); |
| 2909 | ||
|
17088
1ecea6e2fd97
Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17009
diff
changeset
|
2910 | if (font->face && (!oldfont->face || strcmp(font->face, oldfont->face) != 0) && !(options & GTK_IMHTML_NO_FONTS)) |
| 8692 | 2911 | gtk_imhtml_toggle_fontface(imhtml, oldfont->face); |
| 2912 | ||
|
17088
1ecea6e2fd97
Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17009
diff
changeset
|
2913 | if (font->fore && (!oldfont->fore || strcmp(font->fore, oldfont->fore) != 0) && !(options & GTK_IMHTML_NO_COLOURS)) |
| 8692 | 2914 | gtk_imhtml_toggle_forecolor(imhtml, oldfont->fore); |
| 2915 | ||
|
17088
1ecea6e2fd97
Ignore bold, underline and other formatting type things in SPAN tags if
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17009
diff
changeset
|
2916 | if (font->back && (!oldfont->back || strcmp(font->back, oldfont->back) != 0) && !(options & GTK_IMHTML_NO_COLOURS)) |
| 8692 | 2917 | gtk_imhtml_toggle_backcolor(imhtml, oldfont->back); |
| 8686 | 2918 | } |
| 8692 | 2919 | |
| 2920 | g_free (font->face); | |
| 2921 | g_free (font->fore); | |
| 2922 | g_free (font->back); | |
| 2923 | g_free (font->sml); | |
| 2924 | ||
|
8118
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2925 | g_free (font); |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2926 | } |
|
7f5315bb4506
[gaim-migrate @ 8822]
Douglas Thrift <douglas@douglasthrift.net>
parents:
8105
diff
changeset
|
2927 | break; |
| 8026 | 2928 | case 60: /* SPAN */ |
| 2993 | 2929 | break; |
| 8061 | 2930 | case 62: /* comment */ |
|
8177
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
2931 | /* NEW_BIT (NEW_TEXT_BIT); */ |
| 8317 | 2932 | ws[wpos] = '\0'; |
| 9465 | 2933 | |
| 8677 | 2934 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 2935 | ||
|
10815
b1ca28de65d3
[gaim-migrate @ 12470]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10814
diff
changeset
|
2936 | if (imhtml->show_comments && !(options & GTK_IMHTML_NO_COMMENTS)) { |
|
6124
322206d79652
[gaim-migrate @ 6598]
Mark Doliner <markdoliner@pidgin.im>
parents:
6066
diff
changeset
|
2937 | wpos = g_snprintf (ws, len, "%s", tag); |
|
10815
b1ca28de65d3
[gaim-migrate @ 12470]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10814
diff
changeset
|
2938 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
|
b1ca28de65d3
[gaim-migrate @ 12470]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10814
diff
changeset
|
2939 | } |
|
b1ca28de65d3
[gaim-migrate @ 12470]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10814
diff
changeset
|
2940 | ws[0] = '\0'; wpos = 0; |
|
b1ca28de65d3
[gaim-migrate @ 12470]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10814
diff
changeset
|
2941 | |
|
8177
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
2942 | /* NEW_BIT (NEW_COMMENT_BIT); */ |
| 3922 | 2943 | break; |
| 2944 | default: | |
| 6882 | 2945 | break; |
| 2993 | 2946 | } |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2947 | c += tlen; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2948 | pos += tlen; |
|
13138
4d3bd039da3e
[gaim-migrate @ 15499]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13137
diff
changeset
|
2949 | 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
|
2950 | } else if (imhtml->edit.link == NULL && |
|
a8ef18791524
[gaim-migrate @ 18059]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15111
diff
changeset
|
2951 | gtk_imhtml_is_smiley(imhtml, fonts, c, &smilelen)) { |
| 8473 | 2952 | GtkIMHtmlFontDetail *fd; |
| 2953 | ||
| 2954 | gchar *sml = NULL; | |
| 2955 | if (fonts) { | |
| 2956 | fd = fonts->data; | |
| 2957 | sml = fd->sml; | |
| 2958 | } | |
| 9029 | 2959 | if (!sml) |
| 2960 | sml = imhtml->protocol_name; | |
| 2961 | ||
| 8677 | 2962 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8505 | 2963 | wpos = g_snprintf (ws, smilelen + 1, "%s", c); |
| 8473 | 2964 | |
| 8677 | 2965 | gtk_imhtml_insert_smiley_at_iter(imhtml, sml, ws, iter); |
| 8473 | 2966 | |
| 8505 | 2967 | c += smilelen; |
| 2968 | pos += smilelen; | |
| 8473 | 2969 | wpos = 0; |
| 2970 | ws[0] = 0; | |
| 16144 | 2971 | } else if (*c == '&' && (amp = purple_markup_unescape_entity(c, &tlen))) { |
| 7280 | 2972 | while(*amp) { |
| 2973 | ws [wpos++] = *amp++; | |
| 2974 | } | |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2975 | c += tlen; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2976 | pos += tlen; |
| 1428 | 2977 | } else if (*c == '\n') { |
| 2978 | if (!(options & GTK_IMHTML_NO_NEWLINE)) { | |
| 3922 | 2979 | ws[wpos] = '\n'; |
| 2980 | wpos++; | |
| 8677 | 2981 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 2982 | ws[0] = '\0'; |
| 2983 | wpos = 0; | |
|
8177
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
2984 | /* NEW_BIT (NEW_TEXT_BIT); */ |
| 10217 | 2985 | } else if (!br) { /* Don't insert a space immediately after an HTML break */ |
| 9621 | 2986 | /* A newline is defined by HTML as whitespace, which means we have to replace it with a word boundary. |
| 2987 | * word breaks vary depending on the language used, so the correct thing to do is to use Pango to determine | |
| 2988 | * what language this is, determine the proper word boundary to use, and insert that. I'm just going to insert | |
| 2989 | * a space instead. What are the non-English speakers going to do? Complain in a language I'll understand? | |
| 2990 | * Bu-wahaha! */ | |
| 2991 | ws[wpos] = ' '; | |
| 2992 | wpos++; | |
| 2993 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
| 2994 | ws[0] = '\0'; | |
| 2995 | wpos = 0; | |
| 1428 | 2996 | } |
| 2997 | c++; | |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
2998 | pos++; |
| 8334 | 2999 | } else if ((len_protocol = gtk_imhtml_is_protocol(c)) > 0){ |
| 3000 | while(len_protocol--){ | |
| 8677 | 3001 | /* Skip the next len_protocol characters, but make sure they're |
| 8334 | 3002 | copied into the ws array. |
| 3003 | */ | |
| 3004 | ws [wpos++] = *c++; | |
| 3005 | pos++; | |
| 3006 | } | |
| 8061 | 3007 | } else if (*c) { |
| 1428 | 3008 | ws [wpos++] = *c++; |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
3009 | pos++; |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
3010 | } else { |
|
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2826
diff
changeset
|
3011 | break; |
| 1428 | 3012 | } |
| 3013 | } | |
| 8677 | 3014 | gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 3015 | ws[0] = '\0'; wpos = 0; |
| 3016 | ||
|
8177
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
3017 | /* NEW_BIT(NEW_TEXT_BIT); */ |
| 8061 | 3018 | |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3019 | if(align_right) { |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3020 | /* 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
|
3021 | GtkTextIter line_iter; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3022 | line_iter = *iter; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3023 | 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
|
3024 | /* insert RLM character to set alignment */ |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3025 | ws[wpos++] = 0xE2; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3026 | ws[wpos++] = 0x80; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3027 | ws[wpos++] = 0x8F; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3028 | |
| 16144 | 3029 | if (!rtl_direction) |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3030 | { |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3031 | /* insert LRM character to set direction */ |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3032 | /* (alignment=right and direction=LTR) */ |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3033 | ws[wpos++] = 0xE2; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3034 | ws[wpos++] = 0x80; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3035 | ws[wpos++] = 0x8E; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3036 | } |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3037 | |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3038 | ws[wpos] = '\0'; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3039 | 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
|
3040 | 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
|
3041 | ws[0] = '\0'; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3042 | wpos = 0; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3043 | } |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
3044 | |
| 4032 | 3045 | while (fonts) { |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3046 | GtkIMHtmlFontDetail *font = fonts->data; |
| 4032 | 3047 | fonts = g_slist_remove (fonts, font); |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
3048 | g_free (font->face); |
|
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
3049 | g_free (font->fore); |
|
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
3050 | g_free (font->back); |
|
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
3051 | g_free (font->sml); |
| 4032 | 3052 | g_free (font); |
| 3053 | } | |
| 8932 | 3054 | |
| 3055 | g_free(ws); | |
|
13138
4d3bd039da3e
[gaim-migrate @ 15499]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13137
diff
changeset
|
3056 | g_free(bg); |
| 8677 | 3057 | |
| 3058 | if (!imhtml->wbfo) | |
| 8698 | 3059 | gtk_imhtml_close_tags(imhtml, iter); |
| 8506 | 3060 | |
| 15403 | 3061 | object = g_object_ref(G_OBJECT(imhtml)); |
| 8506 | 3062 | g_signal_emit(object, signals[UPDATE_FORMAT], 0); |
| 3063 | g_object_unref(object); | |
| 15420 | 3064 | |
| 3922 | 3065 | } |
| 3066 | ||
| 4892 | 3067 | void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml) |
| 3068 | { | |
| 4288 | 3069 | g_hash_table_destroy(imhtml->smiley_data); |
| 3070 | gtk_smiley_tree_destroy(imhtml->default_smilies); | |
| 4892 | 3071 | imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 4902 | 3072 | g_free, (GDestroyNotify)gtk_smiley_tree_destroy); |
| 4288 | 3073 | imhtml->default_smilies = gtk_smiley_tree_new(); |
| 3074 | } | |
| 8481 | 3075 | |
| 3922 | 3076 | void gtk_imhtml_show_comments (GtkIMHtml *imhtml, |
| 4253 | 3077 | gboolean show) |
| 3078 | { | |
|
6124
322206d79652
[gaim-migrate @ 6598]
Mark Doliner <markdoliner@pidgin.im>
parents:
6066
diff
changeset
|
3079 | imhtml->show_comments = show; |
| 4253 | 3080 | } |
|
1780
431333222954
[gaim-migrate @ 1790]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1738
diff
changeset
|
3081 | |
|
11814
5003711283c0
[gaim-migrate @ 14105]
Richard Laager <rlaager@pidgin.im>
parents:
11768
diff
changeset
|
3082 | const char * |
|
5003711283c0
[gaim-migrate @ 14105]
Richard Laager <rlaager@pidgin.im>
parents:
11768
diff
changeset
|
3083 | gtk_imhtml_get_protocol_name(GtkIMHtml *imhtml) { |
|
5003711283c0
[gaim-migrate @ 14105]
Richard Laager <rlaager@pidgin.im>
parents:
11768
diff
changeset
|
3084 | return imhtml->protocol_name; |
|
5003711283c0
[gaim-migrate @ 14105]
Richard Laager <rlaager@pidgin.im>
parents:
11768
diff
changeset
|
3085 | } |
|
5003711283c0
[gaim-migrate @ 14105]
Richard Laager <rlaager@pidgin.im>
parents:
11768
diff
changeset
|
3086 | |
| 8962 | 3087 | void |
| 9029 | 3088 | 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
|
3089 | g_free(imhtml->protocol_name); |
|
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
3090 | imhtml->protocol_name = g_strdup(protocol_name); |
| 8456 | 3091 | } |
| 3092 | ||
|
1780
431333222954
[gaim-migrate @ 1790]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1738
diff
changeset
|
3093 | void |
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3094 | gtk_imhtml_delete(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) { |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3095 | GList *l; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3096 | GSList *sl; |
|
11234
e23fd86e7581
[gaim-migrate @ 13377]
Daniel Atallah <datallah@pidgin.im>
parents:
11233
diff
changeset
|
3097 | GtkTextIter i, i_s, i_e; |
| 8427 | 3098 | GObject *object = g_object_ref(G_OBJECT(imhtml)); |
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3099 | |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3100 | if (start == NULL) { |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3101 | gtk_text_buffer_get_start_iter(imhtml->text_buffer, &i_s); |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3102 | start = &i_s; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3103 | } |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3104 | |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3105 | if (end == NULL) { |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3106 | gtk_text_buffer_get_end_iter(imhtml->text_buffer, &i_e); |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3107 | end = &i_e; |
| 7991 | 3108 | } |
|
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 | l = imhtml->scalables; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3111 | while (l) { |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3112 | GList *next = l->next; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3113 | struct scalable_data *sd = l->data; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3114 | gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3115 | &i, sd->mark); |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3116 | if (gtk_text_iter_in_range(&i, start, end)) { |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3117 | GtkIMHtmlScalable *scale = sd->scalable; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3118 | scale->free(scale); |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3119 | imhtml->scalables = g_list_remove_link(imhtml->scalables, l); |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3120 | } |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3121 | l = next; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3122 | } |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3123 | |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3124 | sl = imhtml->im_images; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3125 | while (sl) { |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3126 | GSList *next = sl->next; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3127 | struct im_image_data *img_data = sl->data; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3128 | gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3129 | &i, img_data->mark); |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3130 | if (gtk_text_iter_in_range(&i, start, end)) { |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3131 | if (imhtml->funcs->image_unref) |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3132 | imhtml->funcs->image_unref(img_data->id); |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3133 | imhtml->im_images = g_slist_delete_link(imhtml->im_images, sl); |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3134 | g_free(img_data); |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3135 | } |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3136 | sl = next; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3137 | } |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
3138 | gtk_text_buffer_delete(imhtml->text_buffer, start, end); |
| 8061 | 3139 | |
| 8427 | 3140 | g_object_unref(object); |
|
1780
431333222954
[gaim-migrate @ 1790]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
1738
diff
changeset
|
3141 | } |
|
2363
0767c14d7879
[gaim-migrate @ 2376]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2349
diff
changeset
|
3142 | |
| 4046 | 3143 | void gtk_imhtml_page_up (GtkIMHtml *imhtml) |
| 3144 | { | |
| 5282 | 3145 | GdkRectangle rect; |
| 3146 | GtkTextIter iter; | |
| 4046 | 3147 | |
| 5282 | 3148 | gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); |
| 3149 | gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x, | |
| 3150 | rect.y - rect.height); | |
| 3151 | gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0); | |
| 8061 | 3152 | |
| 4046 | 3153 | } |
| 5282 | 3154 | void gtk_imhtml_page_down (GtkIMHtml *imhtml) |
| 3155 | { | |
| 3156 | GdkRectangle rect; | |
| 3157 | GtkTextIter iter; | |
| 3158 | ||
| 3159 | gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); | |
| 3160 | gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x, | |
| 3161 | rect.y + rect.height); | |
| 3162 | gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0); | |
| 3163 | } | |
| 4735 | 3164 | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3165 | /* GtkIMHtmlScalable, gtk_imhtml_image, gtk_imhtml_hr */ |
| 8962 | 3166 | GtkIMHtmlScalable *gtk_imhtml_image_new(GdkPixbuf *img, const gchar *filename, int id) |
| 4735 | 3167 | { |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3168 | GtkIMHtmlImage *im_image = g_malloc(sizeof(GtkIMHtmlImage)); |
| 4895 | 3169 | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3170 | GTK_IMHTML_SCALABLE(im_image)->scale = gtk_imhtml_image_scale; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3171 | 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
|
3172 | GTK_IMHTML_SCALABLE(im_image)->free = gtk_imhtml_image_free; |
| 5046 | 3173 | |
| 3174 | 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
|
3175 | im_image->image = GTK_IMAGE(gtk_image_new_from_pixbuf(im_image->pixbuf)); |
| 4895 | 3176 | im_image->width = gdk_pixbuf_get_width(img); |
| 3177 | im_image->height = gdk_pixbuf_get_height(img); | |
| 3178 | im_image->mark = NULL; | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
3179 | im_image->filename = g_strdup(filename); |
| 8962 | 3180 | im_image->id = id; |
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3181 | im_image->filesel = NULL; |
| 4895 | 3182 | |
| 5046 | 3183 | g_object_ref(img); |
| 4895 | 3184 | return GTK_IMHTML_SCALABLE(im_image); |
| 3185 | } | |
| 3186 | ||
|
18151
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3187 | static gboolean |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3188 | 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
|
3189 | { |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3190 | GtkIMHtmlImage *im_image; |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3191 | int width, height; |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3192 | int delay; |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3193 | |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3194 | im_image = data; |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3195 | |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3196 | /* 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
|
3197 | 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
|
3198 | 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
|
3199 | 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
|
3200 | 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
|
3201 | |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3202 | /* 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
|
3203 | 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
|
3204 | 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
|
3205 | 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
|
3206 | { |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3207 | /* 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
|
3208 | GdkPixbuf *tmp; |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3209 | 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
|
3210 | 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
|
3211 | 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
|
3212 | } else { |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3213 | /* 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
|
3214 | 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
|
3215 | } |
|
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 | 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
|
3218 | 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
|
3219 | |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3220 | return FALSE; |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3221 | } |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3222 | |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3223 | 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
|
3224 | { |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3225 | 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
|
3226 | |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3227 | 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
|
3228 | 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
|
3229 | 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
|
3230 | |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3231 | 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
|
3232 | 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
|
3233 | 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
|
3234 | 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
|
3235 | 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
|
3236 | } else { |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3237 | int delay; |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3238 | 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
|
3239 | 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
|
3240 | 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
|
3241 | 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
|
3242 | } |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3243 | 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
|
3244 | 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
|
3245 | 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
|
3246 | 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
|
3247 | 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
|
3248 | 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
|
3249 | 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
|
3250 | |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3251 | 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
|
3252 | 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
|
3253 | |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3254 | 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
|
3255 | } |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3256 | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3257 | void gtk_imhtml_image_scale(GtkIMHtmlScalable *scale, int width, int height) |
| 4895 | 3258 | { |
|
11867
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3259 | GtkIMHtmlImage *im_image = (GtkIMHtmlImage *)scale; |
|
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3260 | |
|
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3261 | if (im_image->width > width || im_image->height > height) { |
|
11840
c9ec5a42d420
[gaim-migrate @ 14131]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11820
diff
changeset
|
3262 | double ratio_w, ratio_h, ratio; |
|
c9ec5a42d420
[gaim-migrate @ 14131]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11820
diff
changeset
|
3263 | int new_h, new_w; |
| 4895 | 3264 | GdkPixbuf *new_image = NULL; |
|
11840
c9ec5a42d420
[gaim-migrate @ 14131]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11820
diff
changeset
|
3265 | |
|
11867
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3266 | ratio_w = ((double)width - 2) / im_image->width; |
|
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3267 | ratio_h = ((double)height - 2) / im_image->height; |
|
11840
c9ec5a42d420
[gaim-migrate @ 14131]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11820
diff
changeset
|
3268 | |
|
c9ec5a42d420
[gaim-migrate @ 14131]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11820
diff
changeset
|
3269 | ratio = (ratio_w < ratio_h) ? ratio_w : ratio_h; |
|
c9ec5a42d420
[gaim-migrate @ 14131]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11820
diff
changeset
|
3270 | |
|
11867
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3271 | new_w = (int)(im_image->width * ratio); |
|
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3272 | new_h = (int)(im_image->height * ratio); |
|
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3273 | |
|
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3274 | 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
|
3275 | gtk_image_set_from_pixbuf(im_image->image, new_image); |
|
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3276 | g_object_unref(G_OBJECT(new_image)); |
|
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3277 | } 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
|
3278 | /* Enough space to show the full-size of the image. */ |
|
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3279 | GdkPixbuf *new_image; |
|
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3280 | |
|
de448bc5da1a
[gaim-migrate @ 14158]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11844
diff
changeset
|
3281 | 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
|
3282 | gtk_image_set_from_pixbuf(im_image->image, new_image); |
| 4895 | 3283 | g_object_unref(G_OBJECT(new_image)); |
| 3284 | } | |
| 3285 | } | |
| 3286 | ||
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3287 | static void |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3288 | image_save_yes_cb(GtkIMHtmlImage *image, const char *filename) |
| 5012 | 3289 | { |
| 3290 | gchar *type = NULL; | |
| 5019 | 3291 | GError *error = NULL; |
| 5015 | 3292 | #if GTK_CHECK_VERSION(2,2,0) |
| 5012 | 3293 | GSList *formats = gdk_pixbuf_get_formats(); |
|
6162
aed29c41bdfa
[gaim-migrate @ 6642]
Mark Doliner <markdoliner@pidgin.im>
parents:
6124
diff
changeset
|
3294 | #else |
|
aed29c41bdfa
[gaim-migrate @ 6642]
Mark Doliner <markdoliner@pidgin.im>
parents:
6124
diff
changeset
|
3295 | char *basename = g_path_get_basename(filename); |
|
aed29c41bdfa
[gaim-migrate @ 6642]
Mark Doliner <markdoliner@pidgin.im>
parents:
6124
diff
changeset
|
3296 | char *ext = strrchr(basename, '.'); |
|
5959
827dbe4b5bb2
[gaim-migrate @ 6405]
Mark Doliner <markdoliner@pidgin.im>
parents:
5582
diff
changeset
|
3297 | #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
|
3298 | char *newfilename; |
| 5012 | 3299 | |
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3300 | gtk_widget_destroy(image->filesel); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3301 | image->filesel = NULL; |
|
5959
827dbe4b5bb2
[gaim-migrate @ 6405]
Mark Doliner <markdoliner@pidgin.im>
parents:
5582
diff
changeset
|
3302 | |
|
827dbe4b5bb2
[gaim-migrate @ 6405]
Mark Doliner <markdoliner@pidgin.im>
parents:
5582
diff
changeset
|
3303 | #if GTK_CHECK_VERSION(2,2,0) |
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3304 | while (formats) { |
| 5012 | 3305 | GdkPixbufFormat *format = formats->data; |
| 3306 | gchar **extensions = gdk_pixbuf_format_get_extensions(format); | |
| 3307 | gpointer p = extensions; | |
| 3308 | ||
| 3309 | while(gdk_pixbuf_format_is_writable(format) && extensions && extensions[0]){ | |
| 3310 | gchar *fmt_ext = extensions[0]; | |
| 3311 | const gchar* file_ext = filename + strlen(filename) - strlen(fmt_ext); | |
| 3312 | ||
|
17695
5e7fcc2f23cc
Compare the user-entered file extension to the GDK file extension
Mark Doliner <markdoliner@pidgin.im>
parents:
17694
diff
changeset
|
3313 | if(!g_ascii_strcasecmp(fmt_ext, file_ext)){ |
| 5012 | 3314 | type = gdk_pixbuf_format_get_name(format); |
| 3315 | break; | |
| 3316 | } | |
| 3317 | ||
| 3318 | extensions++; | |
| 3319 | } | |
| 3320 | ||
| 3321 | g_strfreev(p); | |
| 3322 | ||
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3323 | if (type) |
| 5012 | 3324 | break; |
| 3325 | ||
| 3326 | formats = formats->next; | |
| 3327 | } | |
| 3328 | ||
| 5020 | 3329 | g_slist_free(formats); |
| 3330 | #else | |
| 3331 | /* 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
|
3332 | if (ext) { |
| 5020 | 3333 | ext++; |
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3334 | if (!g_ascii_strcasecmp(ext, "jpeg") || !g_ascii_strcasecmp(ext, "jpg")) |
| 5020 | 3335 | type = g_strdup("jpeg"); |
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3336 | else if (!g_ascii_strcasecmp(ext, "png")) |
| 5020 | 3337 | type = g_strdup("png"); |
| 3338 | } | |
| 3339 | ||
| 3340 | g_free(basename); | |
| 3341 | #endif | |
| 3342 | ||
| 5012 | 3343 | /* If I can't find a valid type, I will just tell the user about it and then assume |
| 3344 | it's a png */ | |
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3345 | 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
|
3346 | char *basename, *tmp; |
|
11069
3cc1cdd931e9
[gaim-migrate @ 13065]
Richard Laager <rlaager@pidgin.im>
parents:
11019
diff
changeset
|
3347 | #if GTK_CHECK_VERSION(2,4,0) |
|
11019
6786068b00ab
[gaim-migrate @ 12890]
Richard Laager <rlaager@pidgin.im>
parents:
11006
diff
changeset
|
3348 | 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
|
3349 | _("<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
|
3350 | #else |
|
3cc1cdd931e9
[gaim-migrate @ 13065]
Richard Laager <rlaager@pidgin.im>
parents:
11019
diff
changeset
|
3351 | 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
|
3352 | _("Unrecognized file type\n\nDefaulting to PNG.")); |
|
3cc1cdd931e9
[gaim-migrate @ 13065]
Richard Laager <rlaager@pidgin.im>
parents:
11019
diff
changeset
|
3353 | #endif |
|
3cc1cdd931e9
[gaim-migrate @ 13065]
Richard Laager <rlaager@pidgin.im>
parents:
11019
diff
changeset
|
3354 | |
|
11019
6786068b00ab
[gaim-migrate @ 12890]
Richard Laager <rlaager@pidgin.im>
parents:
11006
diff
changeset
|
3355 | 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
|
3356 | 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
|
3357 | |
|
9717
3c8f42ca313e
[gaim-migrate @ 10578]
Mark Doliner <markdoliner@pidgin.im>
parents:
9709
diff
changeset
|
3358 | 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
|
3359 | 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
|
3360 | 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
|
3361 | 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
|
3362 | 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
|
3363 | 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
|
3364 | 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
|
3365 | } 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
|
3366 | /* |
|
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 | * 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
|
3368 | * 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
|
3369 | */ |
|
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 | newfilename = g_strdup(filename); |
| 5012 | 3371 | } |
| 3372 | ||
|
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
|
3373 | 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
|
3374 | |
|
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 | 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
|
3376 | g_free(type); |
| 5012 | 3377 | |
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3378 | if (error){ |
|
11069
3cc1cdd931e9
[gaim-migrate @ 13065]
Richard Laager <rlaager@pidgin.im>
parents:
11019
diff
changeset
|
3379 | #if GTK_CHECK_VERSION(2,4,0) |
|
11019
6786068b00ab
[gaim-migrate @ 12890]
Richard Laager <rlaager@pidgin.im>
parents:
11006
diff
changeset
|
3380 | 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
|
3381 | _("<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
|
3382 | #else |
|
3cc1cdd931e9
[gaim-migrate @ 13065]
Richard Laager <rlaager@pidgin.im>
parents:
11019
diff
changeset
|
3383 | 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
|
3384 | _("Error saving image\n\n%s"), error->message); |
|
3cc1cdd931e9
[gaim-migrate @ 13065]
Richard Laager <rlaager@pidgin.im>
parents:
11019
diff
changeset
|
3385 | #endif |
|
11019
6786068b00ab
[gaim-migrate @ 12890]
Richard Laager <rlaager@pidgin.im>
parents:
11006
diff
changeset
|
3386 | 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
|
3387 | gtk_widget_show(dialog); |
| 5012 | 3388 | g_error_free(error); |
| 3389 | } | |
| 3390 | } | |
| 3391 | ||
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3392 | #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3393 | static void |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3394 | 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
|
3395 | { |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3396 | gchar *filename; |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3397 | |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3398 | if (response != GTK_RESPONSE_ACCEPT) { |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3399 | gtk_widget_destroy(widget); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3400 | image->filesel = NULL; |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3401 | return; |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3402 | } |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3403 | |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3404 | filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget)); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3405 | #else /* FILECHOOSER */ |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3406 | static void |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3407 | image_save_check_if_exists_cb(GtkWidget *button, GtkIMHtmlImage *image) |
| 5012 | 3408 | { |
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3409 | gchar *filename; |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3410 | |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3411 | 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
|
3412 | |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3413 | if (g_file_test(filename, G_FILE_TEST_IS_DIR)) { |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3414 | gchar *dirname; |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3415 | /* append a / is needed */ |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3416 | if (filename[strlen(filename) - 1] != G_DIR_SEPARATOR) { |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3417 | dirname = g_strconcat(filename, G_DIR_SEPARATOR_S, NULL); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3418 | } else { |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3419 | dirname = g_strdup(filename); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3420 | } |
|
9574
d5a2c770adcd
[gaim-migrate @ 10417]
Mark Doliner <markdoliner@pidgin.im>
parents:
9573
diff
changeset
|
3421 | 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
|
3422 | g_free(dirname); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3423 | g_free(filename); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3424 | return; |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3425 | } |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3426 | #endif /* FILECHOOSER */ |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3427 | |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3428 | /* |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3429 | * 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
|
3430 | * 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
|
3431 | * 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
|
3432 | */ |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3433 | /* |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3434 | if (g_file_test(filename, G_FILE_TEST_EXISTS)) { |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3435 | } else |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3436 | image_save_yes_cb(image, filename); |
|
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 | image_save_yes_cb(image, filename); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3440 | |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3441 | g_free(filename); |
|
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 !GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3445 | static void |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3446 | image_save_cancel_cb(GtkIMHtmlImage *image) |
|
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 | gtk_widget_destroy(image->filesel); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3449 | image->filesel = NULL; |
|
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 | #endif /* FILECHOOSER */ |
|
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 | static void |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3454 | gtk_imhtml_image_save(GtkWidget *w, GtkIMHtmlImage *image) |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3455 | { |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3456 | if (image->filesel != NULL) { |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3457 | gtk_window_present(GTK_WINDOW(image->filesel)); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3458 | return; |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3459 | } |
|
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 | #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3462 | image->filesel = gtk_file_chooser_dialog_new(_("Save Image"), |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3463 | NULL, |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3464 | GTK_FILE_CHOOSER_ACTION_SAVE, |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3465 | GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3466 | GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3467 | NULL); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3468 | 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
|
3469 | if (image->filename != NULL) |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3470 | 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
|
3471 | g_signal_connect(G_OBJECT(GTK_FILE_CHOOSER(image->filesel)), "response", |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3472 | G_CALLBACK(image_save_check_if_exists_cb), image); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3473 | #else /* FILECHOOSER */ |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3474 | image->filesel = gtk_file_selection_new(_("Save Image")); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3475 | if (image->filename != NULL) |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3476 | 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
|
3477 | 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
|
3478 | G_CALLBACK(image_save_cancel_cb), image); |
|
d5a2c770adcd
[gaim-migrate @ 10417]
Mark Doliner <markdoliner@pidgin.im>
parents:
9573
diff
changeset
|
3479 | 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
|
3480 | "clicked", G_CALLBACK(image_save_cancel_cb), image); |
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3481 | 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
|
3482 | G_CALLBACK(image_save_check_if_exists_cb), image); |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3483 | #endif /* FILECHOOSER */ |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3484 | |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3485 | gtk_widget_show(image->filesel); |
| 5012 | 3486 | } |
| 3487 | ||
|
9815
fcbbbce0e1ff
[gaim-migrate @ 10686]
Mark Doliner <markdoliner@pidgin.im>
parents:
9726
diff
changeset
|
3488 | /* |
|
fcbbbce0e1ff
[gaim-migrate @ 10686]
Mark Doliner <markdoliner@pidgin.im>
parents:
9726
diff
changeset
|
3489 | * 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
|
3490 | * 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
|
3491 | * basically like file transfer, except there is an icon to open the file |
| 15884 | 3492 | * 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
|
3493 | * all of that. |
|
fcbbbce0e1ff
[gaim-migrate @ 10686]
Mark Doliner <markdoliner@pidgin.im>
parents:
9726
diff
changeset
|
3494 | */ |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3495 | static gboolean gtk_imhtml_image_clicked(GtkWidget *w, GdkEvent *event, GtkIMHtmlImage *image) |
| 5012 | 3496 | { |
| 3497 | GdkEventButton *event_button = (GdkEventButton *) event; | |
| 3498 | ||
| 3499 | if (event->type == GDK_BUTTON_RELEASE) { | |
| 3500 | if(event_button->button == 3) { | |
| 3501 | GtkWidget *img, *item, *menu; | |
| 3502 | gchar *text = g_strdup_printf(_("_Save Image...")); | |
| 3503 | menu = gtk_menu_new(); | |
| 3504 | ||
| 3505 | /* buttons and such */ | |
| 3506 | img = gtk_image_new_from_stock(GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU); | |
| 3507 | item = gtk_image_menu_item_new_with_mnemonic(text); | |
| 3508 | 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
|
3509 | g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(gtk_imhtml_image_save), image); |
| 5012 | 3510 | gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
| 3511 | ||
| 3512 | gtk_widget_show_all(menu); | |
| 3513 | gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, | |
| 3514 | event_button->button, event_button->time); | |
| 3515 | ||
| 3516 | g_free(text); | |
| 3517 | return TRUE; | |
| 3518 | } | |
| 3519 | } | |
| 3520 | if(event->type == GDK_BUTTON_PRESS && event_button->button == 3) | |
| 3521 | return TRUE; /* Clicking the right mouse button on a link shouldn't | |
| 3522 | be caught by the regular GtkTextView menu */ | |
| 3523 | else | |
| 3524 | return FALSE; /* Let clicks go through if we didn't catch anything */ | |
| 3525 | ||
| 3526 | } | |
|
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
|
3527 | |
|
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
|
3528 | 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
|
3529 | { |
|
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
|
3530 | 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
|
3531 | 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
|
3532 | 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
|
3533 | |
|
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
|
3534 | 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
|
3535 | 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
|
3536 | |
|
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 | 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
|
3538 | 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
|
3539 | 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
|
3540 | |
|
18151
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3541 | 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
|
3542 | 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
|
3543 | 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
|
3544 | 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
|
3545 | } |
|
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 | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3547 | void gtk_imhtml_image_free(GtkIMHtmlScalable *scale) |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3548 | { |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3549 | GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3550 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3551 | g_object_unref(image->pixbuf); |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
3552 | g_free(image->filename); |
|
9573
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3553 | if (image->filesel) |
|
7fb26654aee8
[gaim-migrate @ 10416]
Mark Doliner <markdoliner@pidgin.im>
parents:
9467
diff
changeset
|
3554 | gtk_widget_destroy(image->filesel); |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3555 | g_free(scale); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3556 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3557 | |
|
18151
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3558 | 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
|
3559 | { |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3560 | 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
|
3561 | |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3562 | 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
|
3563 | 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
|
3564 | 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
|
3565 | 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
|
3566 | 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
|
3567 | |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3568 | 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
|
3569 | } |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
3570 | |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3571 | 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
|
3572 | { |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3573 | GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3574 | GtkWidget *box = gtk_event_box_new(); |
| 8962 | 3575 | char *tag; |
|
5967
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3576 | 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
|
3577 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3578 | gtk_container_add(GTK_CONTAINER(box), GTK_WIDGET(image->image)); |
| 9229 | 3579 | |
| 3580 | if(!gtk_check_version(2, 4, 0)) | |
| 3581 | g_object_set(G_OBJECT(box), "visible-window", FALSE, NULL); | |
|
5967
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 | gtk_widget_show(GTK_WIDGET(image->image)); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3584 | gtk_widget_show(box); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3585 | |
| 8962 | 3586 | tag = g_strdup_printf("<IMG ID=\"%d\">", image->id); |
| 3587 | g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_htmltext", tag, g_free); | |
| 3588 | g_object_set_data(G_OBJECT(anchor), "gtkimhtml_plaintext", "[Image]"); | |
| 3589 | ||
| 15420 | 3590 | 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
|
3591 | 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
|
3592 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3593 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3594 | GtkIMHtmlScalable *gtk_imhtml_hr_new() |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3595 | { |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3596 | GtkIMHtmlHr *hr = g_malloc(sizeof(GtkIMHtmlHr)); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3597 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3598 | GTK_IMHTML_SCALABLE(hr)->scale = gtk_imhtml_hr_scale; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3599 | GTK_IMHTML_SCALABLE(hr)->add_to = gtk_imhtml_hr_add_to; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3600 | GTK_IMHTML_SCALABLE(hr)->free = gtk_imhtml_hr_free; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3601 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3602 | hr->sep = gtk_hseparator_new(); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3603 | gtk_widget_set_size_request(hr->sep, 5000, 2); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3604 | gtk_widget_show(hr->sep); |
|
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 | return GTK_IMHTML_SCALABLE(hr); |
|
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 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3609 | void gtk_imhtml_hr_scale(GtkIMHtmlScalable *scale, int width, int height) |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3610 | { |
|
8588
6bcf7ed80ed8
[gaim-migrate @ 9339]
Mark Doliner <markdoliner@pidgin.im>
parents:
8568
diff
changeset
|
3611 | 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
|
3612 | } |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3613 | |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3614 | 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
|
3615 | { |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3616 | GtkIMHtmlHr *hr = (GtkIMHtmlHr *)scale; |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3617 | GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); |
| 8698 | 3618 | g_object_set_data(G_OBJECT(anchor), "gtkimhtml_htmltext", "<hr>"); |
| 3619 | g_object_set_data(G_OBJECT(anchor), "gtkimhtml_plaintext", "\n---\n"); | |
| 15420 | 3620 | 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
|
3621 | } |
|
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 | void gtk_imhtml_hr_free(GtkIMHtmlScalable *scale) |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3624 | { |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3625 | g_free(scale); |
|
df8268ccde45
[gaim-migrate @ 6414]
Mark Doliner <markdoliner@pidgin.im>
parents:
5966
diff
changeset
|
3626 | } |
| 7295 | 3627 | |
| 3628 | gboolean gtk_imhtml_search_find(GtkIMHtml *imhtml, const gchar *text) | |
| 3629 | { | |
| 3630 | GtkTextIter iter, start, end; | |
| 3631 | gboolean new_search = TRUE; | |
|
14863
82888d51234c
[gaim-migrate @ 17566]
Daniel Atallah <datallah@pidgin.im>
parents:
14821
diff
changeset
|
3632 | GtkTextMark *start_mark; |
| 7295 | 3633 | |
| 3634 | g_return_val_if_fail(imhtml != NULL, FALSE); | |
| 3635 | g_return_val_if_fail(text != NULL, FALSE); | |
| 8061 | 3636 | |
|
14863
82888d51234c
[gaim-migrate @ 17566]
Daniel Atallah <datallah@pidgin.im>
parents:
14821
diff
changeset
|
3637 | start_mark = gtk_text_buffer_get_mark(imhtml->text_buffer, "search"); |
|
82888d51234c
[gaim-migrate @ 17566]
Daniel Atallah <datallah@pidgin.im>
parents:
14821
diff
changeset
|
3638 | |
|
82888d51234c
[gaim-migrate @ 17566]
Daniel Atallah <datallah@pidgin.im>
parents:
14821
diff
changeset
|
3639 | if (start_mark && imhtml->search_string && !strcmp(text, imhtml->search_string)) |
| 7295 | 3640 | new_search = FALSE; |
| 8061 | 3641 | |
| 7295 | 3642 | if (new_search) { |
| 3643 | gtk_imhtml_search_clear(imhtml); | |
|
14863
82888d51234c
[gaim-migrate @ 17566]
Daniel Atallah <datallah@pidgin.im>
parents:
14821
diff
changeset
|
3644 | g_free(imhtml->search_string); |
|
82888d51234c
[gaim-migrate @ 17566]
Daniel Atallah <datallah@pidgin.im>
parents:
14821
diff
changeset
|
3645 | imhtml->search_string = g_strdup(text); |
| 15093 | 3646 | gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); |
| 7295 | 3647 | } else { |
| 3648 | 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
|
3649 | start_mark); |
| 7295 | 3650 | } |
| 3651 | ||
| 15093 | 3652 | if (gtk_source_iter_backward_search(&iter, imhtml->search_string, |
|
14400
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3653 | GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_CASE_INSENSITIVE, |
|
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3654 | &start, &end, NULL)) |
|
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3655 | { |
| 7295 | 3656 | gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &start, 0, TRUE, 0, 0); |
| 15093 | 3657 | 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
|
3658 | if (new_search) |
|
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3659 | { |
| 7295 | 3660 | gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &iter, &end); |
| 8061 | 3661 | do |
| 7295 | 3662 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "search", &start, &end); |
| 15093 | 3663 | while (gtk_source_iter_backward_search(&start, imhtml->search_string, |
| 8061 | 3664 | GTK_SOURCE_SEARCH_VISIBLE_ONLY | |
| 7358 | 3665 | GTK_SOURCE_SEARCH_CASE_INSENSITIVE, |
| 7295 | 3666 | &start, &end, NULL)); |
| 3667 | } | |
| 3668 | return TRUE; | |
| 3669 | } | |
|
14400
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3670 | else if (!new_search) |
|
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3671 | { |
|
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3672 | /* We hit the end, so start at the beginning again. */ |
| 15093 | 3673 | gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); |
| 3674 | ||
| 3675 | if (gtk_source_iter_backward_search(&iter, imhtml->search_string, | |
|
14400
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3676 | GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_CASE_INSENSITIVE, |
|
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3677 | &start, &end, NULL)) |
|
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3678 | { |
|
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3679 | gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &start, 0, TRUE, 0, 0); |
| 15093 | 3680 | 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
|
3681 | |
|
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3682 | return TRUE; |
|
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3683 | } |
|
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3684 | |
|
953baf2eba1a
[gaim-migrate @ 17035]
Richard Laager <rlaager@pidgin.im>
parents:
14395
diff
changeset
|
3685 | } |
| 8061 | 3686 | |
| 7295 | 3687 | return FALSE; |
| 3688 | } | |
| 3689 | ||
| 3690 | void gtk_imhtml_search_clear(GtkIMHtml *imhtml) | |
| 3691 | { | |
| 3692 | GtkTextIter start, end; | |
| 8061 | 3693 | |
| 7295 | 3694 | g_return_if_fail(imhtml != NULL); |
| 8061 | 3695 | |
| 7295 | 3696 | gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); |
| 3697 | gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
| 3698 | ||
| 3699 | 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
|
3700 | g_free(imhtml->search_string); |
| 7295 | 3701 | imhtml->search_string = NULL; |
| 3702 | } | |
| 8061 | 3703 | |
| 8677 | 3704 | static GtkTextTag *find_font_forecolor_tag(GtkIMHtml *imhtml, gchar *color) |
| 3705 | { | |
| 3706 | gchar str[18]; | |
| 3707 | GtkTextTag *tag; | |
| 3708 | ||
| 3709 | g_snprintf(str, sizeof(str), "FORECOLOR %s", color); | |
| 3710 | ||
| 3711 | tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
| 10858 | 3712 | if (!tag) { |
| 3713 | GdkColor gcolor; | |
| 3714 | if (!gdk_color_parse(color, &gcolor)) { | |
| 3715 | gchar tmp[8]; | |
| 3716 | tmp[0] = '#'; | |
| 3717 | strncpy(&tmp[1], color, 7); | |
| 3718 | tmp[7] = '\0'; | |
| 3719 | if (!gdk_color_parse(tmp, &gcolor)) | |
| 3720 | gdk_color_parse("black", &gcolor); | |
| 3721 | } | |
| 3722 | tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground-gdk", &gcolor, NULL); | |
| 3723 | } | |
| 8677 | 3724 | |
| 3725 | return tag; | |
| 3726 | } | |
| 3727 | ||
| 3728 | static GtkTextTag *find_font_backcolor_tag(GtkIMHtml *imhtml, gchar *color) | |
| 3729 | { | |
| 3730 | gchar str[18]; | |
| 3731 | GtkTextTag *tag; | |
| 3732 | ||
| 3733 | g_snprintf(str, sizeof(str), "BACKCOLOR %s", color); | |
| 3734 | ||
| 3735 | tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
| 10858 | 3736 | if (!tag) { |
| 3737 | GdkColor gcolor; | |
| 3738 | if (!gdk_color_parse(color, &gcolor)) { | |
| 3739 | gchar tmp[8]; | |
| 3740 | tmp[0] = '#'; | |
| 3741 | strncpy(&tmp[1], color, 7); | |
| 3742 | tmp[7] = '\0'; | |
| 3743 | if (!gdk_color_parse(tmp, &gcolor)) | |
| 3744 | gdk_color_parse("white", &gcolor); | |
| 3745 | } | |
| 3746 | tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "background-gdk", &gcolor, NULL); | |
| 3747 | } | |
| 8677 | 3748 | |
| 3749 | return tag; | |
| 3750 | } | |
| 3751 | ||
| 10776 | 3752 | static GtkTextTag *find_font_background_tag(GtkIMHtml *imhtml, gchar *color) |
| 3753 | { | |
| 3754 | gchar str[19]; | |
| 3755 | GtkTextTag *tag; | |
| 3756 | ||
| 3757 | g_snprintf(str, sizeof(str), "BACKGROUND %s", color); | |
| 3758 | ||
| 3759 | tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
| 3760 | if (!tag) | |
| 3761 | tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, NULL); | |
| 3762 | ||
| 3763 | return tag; | |
| 3764 | } | |
| 3765 | ||
| 8677 | 3766 | static GtkTextTag *find_font_face_tag(GtkIMHtml *imhtml, gchar *face) |
| 8061 | 3767 | { |
| 8677 | 3768 | gchar str[256]; |
| 3769 | GtkTextTag *tag; | |
| 3770 | ||
| 3771 | g_snprintf(str, sizeof(str), "FONT FACE %s", face); | |
| 3772 | str[255] = '\0'; | |
| 3773 | ||
| 3774 | tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
| 3775 | if (!tag) | |
| 3776 | tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "family", face, NULL); | |
| 3777 | ||
| 3778 | return tag; | |
| 3779 | } | |
| 3780 | ||
| 3781 | static GtkTextTag *find_font_size_tag(GtkIMHtml *imhtml, int size) | |
| 3782 | { | |
| 3783 | gchar str[24]; | |
| 3784 | GtkTextTag *tag; | |
| 3785 | ||
| 3786 | g_snprintf(str, sizeof(str), "FONT SIZE %d", size); | |
| 3787 | str[23] = '\0'; | |
| 3788 | ||
| 3789 | tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
| 3790 | if (!tag) { | |
| 10525 | 3791 | /* For reasons I don't understand, setting "scale" here scaled |
| 3792 | * based on some default size other than my theme's default | |
| 3793 | * size. Our size 4 was actually smaller than our size 3 for | |
| 3794 | * me. So this works around that oddity. | |
| 8677 | 3795 | */ |
| 10525 | 3796 | GtkTextAttributes *attr = gtk_text_view_get_default_attributes(GTK_TEXT_VIEW(imhtml)); |
| 8677 | 3797 | tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "size", |
| 10525 | 3798 | (gint) (pango_font_description_get_size(attr->font) * |
|
10899
87d9aec5b72d
[gaim-migrate @ 12619]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10871
diff
changeset
|
3799 | (double) POINT_SIZE(size)), NULL); |
| 10525 | 3800 | gtk_text_attributes_unref(attr); |
| 8061 | 3801 | } |
| 3802 | ||
| 8677 | 3803 | return tag; |
| 3804 | } | |
| 3805 | ||
| 3806 | static void remove_tag_by_prefix(GtkIMHtml *imhtml, const GtkTextIter *i, const GtkTextIter *e, | |
| 3807 | const char *prefix, guint len, gboolean homo) | |
| 3808 | { | |
| 3809 | GSList *tags, *l; | |
| 3810 | GtkTextIter iter; | |
| 3811 | ||
| 3812 | tags = gtk_text_iter_get_tags(i); | |
| 3813 | ||
| 3814 | for (l = tags; l; l = l->next) { | |
| 3815 | GtkTextTag *tag = l->data; | |
| 3816 | ||
| 3817 | if (tag->name && !strncmp(tag->name, prefix, len)) | |
| 3818 | gtk_text_buffer_remove_tag(imhtml->text_buffer, tag, i, e); | |
| 8061 | 3819 | } |
| 3820 | ||
| 8677 | 3821 | g_slist_free(tags); |
| 3822 | ||
| 3823 | if (homo) | |
| 3824 | return; | |
| 3825 | ||
| 3826 | iter = *i; | |
| 3827 | ||
| 3828 | while (gtk_text_iter_forward_char(&iter) && !gtk_text_iter_equal(&iter, e)) { | |
| 3829 | if (gtk_text_iter_begins_tag(&iter, NULL)) { | |
| 3830 | tags = gtk_text_iter_get_toggled_tags(&iter, TRUE); | |
| 3831 | ||
| 3832 | for (l = tags; l; l = l->next) { | |
| 3833 | GtkTextTag *tag = l->data; | |
| 3834 | ||
| 3835 | if (tag->name && !strncmp(tag->name, prefix, len)) | |
| 3836 | gtk_text_buffer_remove_tag(imhtml->text_buffer, tag, &iter, e); | |
| 3837 | } | |
| 3838 | ||
| 3839 | g_slist_free(tags); | |
| 3840 | } | |
| 8061 | 3841 | } |
| 8677 | 3842 | } |
| 3843 | ||
| 3844 | static void remove_font_size(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
| 3845 | { | |
| 3846 | remove_tag_by_prefix(imhtml, i, e, "FONT SIZE ", 10, homo); | |
| 3847 | } | |
| 3848 | ||
| 3849 | static void remove_font_face(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
| 3850 | { | |
| 3851 | remove_tag_by_prefix(imhtml, i, e, "FONT FACE ", 10, homo); | |
| 3852 | } | |
| 3853 | ||
| 3854 | static void remove_font_forecolor(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
| 3855 | { | |
| 3856 | remove_tag_by_prefix(imhtml, i, e, "FORECOLOR ", 10, homo); | |
| 3857 | } | |
| 3858 | ||
| 3859 | static void remove_font_backcolor(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
| 3860 | { | |
| 3861 | remove_tag_by_prefix(imhtml, i, e, "BACKCOLOR ", 10, homo); | |
| 3862 | } | |
| 3863 | ||
| 10776 | 3864 | static void remove_font_background(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) |
| 3865 | { | |
| 3866 | remove_tag_by_prefix(imhtml, i, e, "BACKGROUND ", 10, homo); | |
| 3867 | } | |
| 3868 | ||
| 8677 | 3869 | static void remove_font_link(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) |
| 3870 | { | |
| 3871 | remove_tag_by_prefix(imhtml, i, e, "LINK ", 5, homo); | |
| 3872 | } | |
| 3873 | ||
|
12672
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3874 | static void |
|
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3875 | imhtml_clear_formatting(GtkIMHtml *imhtml) |
|
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3876 | { |
|
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3877 | GtkTextIter start, end; |
|
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3878 | |
|
12796
8fb3611a91e1
[gaim-migrate @ 15143]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12673
diff
changeset
|
3879 | if (!imhtml->editable) |
|
8fb3611a91e1
[gaim-migrate @ 15143]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12673
diff
changeset
|
3880 | return; |
|
8fb3611a91e1
[gaim-migrate @ 15143]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12673
diff
changeset
|
3881 | |
|
8fb3611a91e1
[gaim-migrate @ 15143]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12673
diff
changeset
|
3882 | if (imhtml->wbfo) |
|
8fb3611a91e1
[gaim-migrate @ 15143]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12673
diff
changeset
|
3883 | gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
|
8fb3611a91e1
[gaim-migrate @ 15143]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12673
diff
changeset
|
3884 | else |
|
8fb3611a91e1
[gaim-migrate @ 15143]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12673
diff
changeset
|
3885 | 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
|
3886 | 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
|
3887 | |
|
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3888 | 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
|
3889 | 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
|
3890 | 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
|
3891 | 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
|
3892 | remove_font_size(imhtml, &start, &end, FALSE); |
|
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3893 | remove_font_face(imhtml, &start, &end, FALSE); |
|
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3894 | remove_font_forecolor(imhtml, &start, &end, FALSE); |
|
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3895 | remove_font_backcolor(imhtml, &start, &end, FALSE); |
|
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3896 | remove_font_background(imhtml, &start, &end, FALSE); |
|
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3897 | remove_font_link(imhtml, &start, &end, FALSE); |
|
12672
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3898 | |
|
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3899 | imhtml->edit.bold = 0; |
|
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3900 | imhtml->edit.italic = 0; |
|
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3901 | imhtml->edit.underline = 0; |
|
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3902 | imhtml->edit.strike = 0; |
|
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3903 | imhtml->edit.fontsize = 0; |
|
13224
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3904 | |
|
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3905 | g_free(imhtml->edit.fontface); |
|
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3906 | imhtml->edit.fontface = NULL; |
|
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3907 | |
|
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3908 | g_free(imhtml->edit.forecolor); |
|
12672
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3909 | imhtml->edit.forecolor = NULL; |
|
13224
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3910 | |
|
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3911 | g_free(imhtml->edit.backcolor); |
|
12672
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3912 | imhtml->edit.backcolor = NULL; |
|
13224
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3913 | |
|
485977c61b47
[gaim-migrate @ 15587]
Richard Laager <rlaager@pidgin.im>
parents:
13138
diff
changeset
|
3914 | g_free(imhtml->edit.background); |
|
12672
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3915 | imhtml->edit.background = NULL; |
|
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3916 | } |
|
673e2a1d2954
[gaim-migrate @ 15015]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12635
diff
changeset
|
3917 | |
| 8677 | 3918 | /* Editable stuff */ |
| 3919 | static void preinsert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml) | |
| 3920 | { | |
| 3921 | imhtml->insert_offset = gtk_text_iter_get_offset(iter); | |
| 3922 | } | |
| 3923 | ||
| 10169 | 3924 | static void insert_ca_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextChildAnchor *arg2, gpointer user_data) |
| 3925 | { | |
| 3926 | GtkTextIter start; | |
| 3927 | ||
| 3928 | start = *arg1; | |
| 3929 | gtk_text_iter_backward_char(&start); | |
| 3930 | ||
| 3931 | gtk_imhtml_apply_tags_on_insert(user_data, &start, arg1); | |
| 3932 | } | |
| 3933 | ||
| 8677 | 3934 | static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *end, gchar *text, gint len, GtkIMHtml *imhtml) |
| 3935 | { | |
| 3936 | GtkTextIter start; | |
| 3937 | ||
| 3938 | if (!len) | |
| 3939 | return; | |
| 3940 | ||
| 3941 | start = *end; | |
| 3942 | gtk_text_iter_set_offset(&start, imhtml->insert_offset); | |
| 3943 | ||
| 10169 | 3944 | gtk_imhtml_apply_tags_on_insert(imhtml, &start, end); |
| 3945 | } | |
| 3946 | ||
|
12673
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3947 | 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
|
3948 | { |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3949 | GSList *tags, *l; |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3950 | |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3951 | tags = gtk_text_iter_get_tags(start); |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3952 | for (l = tags; l != NULL; l = l->next) { |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3953 | GtkTextTag *tag = GTK_TEXT_TAG(l->data); |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3954 | |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3955 | if (tag && /* Remove the formatting only if */ |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3956 | gtk_text_iter_starts_word(start) && /* beginning of a word */ |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3957 | 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
|
3958 | (!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
|
3959 | gtk_text_iter_ends_tag(end, tag))) { |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3960 | 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
|
3961 | if (tag->name && |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3962 | strncmp(tag->name, "LINK ", 5) == 0 && imhtml->edit.link) { |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3963 | gtk_imhtml_toggle_link(imhtml, NULL); |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3964 | } |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
3965 | } |
|
12673
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3966 | } |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3967 | g_slist_free(tags); |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3968 | } |
|
4c8a20955e0b
[gaim-migrate @ 15016]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12672
diff
changeset
|
3969 | |
| 10169 | 3970 | static void gtk_imhtml_apply_tags_on_insert(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) |
| 3971 | { | |
| 8677 | 3972 | if (imhtml->edit.bold) |
| 10169 | 3973 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", start, end); |
| 8677 | 3974 | else |
| 10169 | 3975 | gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", start, end); |
| 8677 | 3976 | |
| 3977 | if (imhtml->edit.italic) | |
| 10169 | 3978 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", start, end); |
| 8677 | 3979 | else |
| 10169 | 3980 | gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", start, end); |
| 8677 | 3981 | |
| 3982 | if (imhtml->edit.underline) | |
| 10169 | 3983 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", start, end); |
| 8677 | 3984 | else |
| 10169 | 3985 | gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", start, end); |
| 8677 | 3986 | |
| 9924 | 3987 | if (imhtml->edit.strike) |
| 10169 | 3988 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", start, end); |
| 9924 | 3989 | else |
| 10169 | 3990 | gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", start, end); |
| 9924 | 3991 | |
| 8677 | 3992 | if (imhtml->edit.forecolor) { |
| 10169 | 3993 | remove_font_forecolor(imhtml, start, end, TRUE); |
| 8677 | 3994 | gtk_text_buffer_apply_tag(imhtml->text_buffer, |
| 3995 | find_font_forecolor_tag(imhtml, imhtml->edit.forecolor), | |
| 10169 | 3996 | start, end); |
| 8061 | 3997 | } |
| 3998 | ||
| 8677 | 3999 | if (imhtml->edit.backcolor) { |
| 10169 | 4000 | remove_font_backcolor(imhtml, start, end, TRUE); |
| 8677 | 4001 | gtk_text_buffer_apply_tag(imhtml->text_buffer, |
| 4002 | find_font_backcolor_tag(imhtml, imhtml->edit.backcolor), | |
| 10169 | 4003 | start, end); |
| 8677 | 4004 | } |
| 4005 | ||
| 10776 | 4006 | if (imhtml->edit.background) { |
| 4007 | remove_font_background(imhtml, start, end, TRUE); | |
| 4008 | gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 4009 | find_font_background_tag(imhtml, imhtml->edit.background), | |
| 4010 | start, end); | |
| 4011 | } | |
| 8677 | 4012 | if (imhtml->edit.fontface) { |
| 10169 | 4013 | remove_font_face(imhtml, start, end, TRUE); |
| 8677 | 4014 | gtk_text_buffer_apply_tag(imhtml->text_buffer, |
| 4015 | find_font_face_tag(imhtml, imhtml->edit.fontface), | |
| 10169 | 4016 | start, end); |
| 8061 | 4017 | } |
| 8677 | 4018 | |
| 4019 | if (imhtml->edit.fontsize) { | |
| 10169 | 4020 | remove_font_size(imhtml, start, end, TRUE); |
| 8677 | 4021 | gtk_text_buffer_apply_tag(imhtml->text_buffer, |
| 4022 | find_font_size_tag(imhtml, imhtml->edit.fontsize), | |
| 10169 | 4023 | start, end); |
| 8677 | 4024 | } |
| 4025 | ||
| 4026 | if (imhtml->edit.link) { | |
| 10169 | 4027 | remove_font_link(imhtml, start, end, TRUE); |
| 8677 | 4028 | gtk_text_buffer_apply_tag(imhtml->text_buffer, |
| 4029 | imhtml->edit.link, | |
| 10169 | 4030 | start, end); |
| 8677 | 4031 | } |
| 8061 | 4032 | } |
| 4033 | ||
| 4034 | void gtk_imhtml_set_editable(GtkIMHtml *imhtml, gboolean editable) | |
| 4035 | { | |
| 4036 | gtk_text_view_set_editable(GTK_TEXT_VIEW(imhtml), editable); | |
|
8177
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
4037 | /* |
|
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
4038 | * We need a visible caret for accessibility, so mouseless |
|
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
4039 | * people can highlight stuff. |
|
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
4040 | */ |
|
33b3a01c6318
[gaim-migrate @ 8891]
Mark Doliner <markdoliner@pidgin.im>
parents:
8149
diff
changeset
|
4041 | /* gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(imhtml), editable); */ |
| 8061 | 4042 | imhtml->editable = editable; |
| 8677 | 4043 | imhtml->format_functions = GTK_IMHTML_ALL; |
| 4044 | ||
| 4045 | if (editable) | |
| 4046 | g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set", | |
| 4047 | G_CALLBACK(mark_set_cb), imhtml); | |
| 4048 | } | |
| 4049 | ||
| 4050 | void gtk_imhtml_set_whole_buffer_formatting_only(GtkIMHtml *imhtml, gboolean wbfo) | |
| 4051 | { | |
| 4052 | g_return_if_fail(imhtml != NULL); | |
| 4053 | ||
| 4054 | imhtml->wbfo = wbfo; | |
| 8420 | 4055 | } |
| 4056 | ||
| 4057 | void gtk_imhtml_set_format_functions(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons) | |
| 4058 | { | |
| 4059 | GObject *object = g_object_ref(G_OBJECT(imhtml)); | |
| 8677 | 4060 | imhtml->format_functions = buttons; |
| 8420 | 4061 | g_signal_emit(object, signals[BUTTONS_UPDATE], 0, buttons); |
| 4062 | g_object_unref(object); | |
| 8061 | 4063 | } |
| 4064 | ||
|
8788
a13634443a38
[gaim-migrate @ 9550]
Mark Doliner <markdoliner@pidgin.im>
parents:
8786
diff
changeset
|
4065 | GtkIMHtmlButtons gtk_imhtml_get_format_functions(GtkIMHtml *imhtml) |
|
a13634443a38
[gaim-migrate @ 9550]
Mark Doliner <markdoliner@pidgin.im>
parents:
8786
diff
changeset
|
4066 | { |
|
a13634443a38
[gaim-migrate @ 9550]
Mark Doliner <markdoliner@pidgin.im>
parents:
8786
diff
changeset
|
4067 | return imhtml->format_functions; |
|
a13634443a38
[gaim-migrate @ 9550]
Mark Doliner <markdoliner@pidgin.im>
parents:
8786
diff
changeset
|
4068 | } |
| 8516 | 4069 | |
| 4070 | void gtk_imhtml_get_current_format(GtkIMHtml *imhtml, gboolean *bold, | |
| 4071 | gboolean *italic, gboolean *underline) | |
| 8481 | 4072 | { |
|
12900
7fe519669e07
[gaim-migrate @ 15253]
Richard Laager <rlaager@pidgin.im>
parents:
12836
diff
changeset
|
4073 | if (bold != NULL) |
|
7fe519669e07
[gaim-migrate @ 15253]
Richard Laager <rlaager@pidgin.im>
parents:
12836
diff
changeset
|
4074 | (*bold) = imhtml->edit.bold; |
|
7fe519669e07
[gaim-migrate @ 15253]
Richard Laager <rlaager@pidgin.im>
parents:
12836
diff
changeset
|
4075 | if (italic != NULL) |
|
7fe519669e07
[gaim-migrate @ 15253]
Richard Laager <rlaager@pidgin.im>
parents:
12836
diff
changeset
|
4076 | (*italic) = imhtml->edit.italic; |
|
7fe519669e07
[gaim-migrate @ 15253]
Richard Laager <rlaager@pidgin.im>
parents:
12836
diff
changeset
|
4077 | if (underline != NULL) |
|
7fe519669e07
[gaim-migrate @ 15253]
Richard Laager <rlaager@pidgin.im>
parents:
12836
diff
changeset
|
4078 | (*underline) = imhtml->edit.underline; |
| 8481 | 4079 | } |
| 4080 | ||
| 9025 | 4081 | char * |
| 4082 | gtk_imhtml_get_current_fontface(GtkIMHtml *imhtml) | |
| 4083 | { | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
4084 | return g_strdup(imhtml->edit.fontface); |
| 9025 | 4085 | } |
| 4086 | ||
| 4087 | char * | |
| 4088 | gtk_imhtml_get_current_forecolor(GtkIMHtml *imhtml) | |
| 4089 | { | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
4090 | return g_strdup(imhtml->edit.forecolor); |
| 9025 | 4091 | } |
| 4092 | ||
| 4093 | char * | |
| 4094 | gtk_imhtml_get_current_backcolor(GtkIMHtml *imhtml) | |
| 4095 | { | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
4096 | return g_strdup(imhtml->edit.backcolor); |
| 9025 | 4097 | } |
| 4098 | ||
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4099 | char * |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4100 | gtk_imhtml_get_current_background(GtkIMHtml *imhtml) |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4101 | { |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
4102 | return g_strdup(imhtml->edit.background); |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4103 | } |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4104 | |
| 9025 | 4105 | gint |
| 4106 | gtk_imhtml_get_current_fontsize(GtkIMHtml *imhtml) | |
| 4107 | { | |
| 4108 | return imhtml->edit.fontsize; | |
| 4109 | } | |
| 4110 | ||
| 8061 | 4111 | gboolean gtk_imhtml_get_editable(GtkIMHtml *imhtml) |
| 4112 | { | |
| 4113 | return imhtml->editable; | |
| 4114 | } | |
| 4115 | ||
|
11269
ca63789d57b9
[gaim-migrate @ 13451]
Richard Laager <rlaager@pidgin.im>
parents:
11267
diff
changeset
|
4116 | void |
|
ca63789d57b9
[gaim-migrate @ 13451]
Richard Laager <rlaager@pidgin.im>
parents:
11267
diff
changeset
|
4117 | gtk_imhtml_clear_formatting(GtkIMHtml *imhtml) |
|
ca63789d57b9
[gaim-migrate @ 13451]
Richard Laager <rlaager@pidgin.im>
parents:
11267
diff
changeset
|
4118 | { |
|
11275
cdcc651d7ecd
[gaim-migrate @ 13461]
Richard Laager <rlaager@pidgin.im>
parents:
11269
diff
changeset
|
4119 | GObject *object; |
|
cdcc651d7ecd
[gaim-migrate @ 13461]
Richard Laager <rlaager@pidgin.im>
parents:
11269
diff
changeset
|
4120 | |
|
cdcc651d7ecd
[gaim-migrate @ 13461]
Richard Laager <rlaager@pidgin.im>
parents:
11269
diff
changeset
|
4121 | object = g_object_ref(G_OBJECT(imhtml)); |
|
cdcc651d7ecd
[gaim-migrate @ 13461]
Richard Laager <rlaager@pidgin.im>
parents:
11269
diff
changeset
|
4122 | g_signal_emit(object, signals[CLEAR_FORMAT], 0); |
|
11276
aec923529d31
[gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents:
11275
diff
changeset
|
4123 | |
|
11269
ca63789d57b9
[gaim-migrate @ 13451]
Richard Laager <rlaager@pidgin.im>
parents:
11267
diff
changeset
|
4124 | gtk_widget_grab_focus(GTK_WIDGET(imhtml)); |
|
11276
aec923529d31
[gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents:
11275
diff
changeset
|
4125 | |
|
aec923529d31
[gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents:
11275
diff
changeset
|
4126 | g_object_unref(object); |
|
11269
ca63789d57b9
[gaim-migrate @ 13451]
Richard Laager <rlaager@pidgin.im>
parents:
11267
diff
changeset
|
4127 | } |
|
ca63789d57b9
[gaim-migrate @ 13451]
Richard Laager <rlaager@pidgin.im>
parents:
11267
diff
changeset
|
4128 | |
| 8677 | 4129 | /* |
| 4130 | * I had this crazy idea about changing the text cursor color to reflex the foreground color | |
| 4131 | * of the text about to be entered. This is the place you'd do it, along with the place where | |
| 4132 | * we actually set a new foreground color. | |
| 15884 | 4133 | * I may not do this, because people will bitch about Purple overriding their gtk theme's cursor |
| 8677 | 4134 | * colors. |
| 4135 | * | |
| 4136 | * Just in case I do do this, I asked about what to set the secondary text cursor to. | |
| 4137 | * | |
| 8719 | 4138 | * (12:45:27) ?? ???: secondary_cursor_color = (rgb(background) + rgb(primary_cursor_color) ) / 2 |
| 4139 | * (12:45:55) ?? ???: understand? | |
| 8677 | 4140 | * (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
|
4141 | * (12:46:56) ?? ???: u might need to extract separate each color from RGB |
| 8677 | 4142 | */ |
| 4143 | ||
| 4144 | static void mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, | |
| 4145 | GtkIMHtml *imhtml) | |
| 4146 | { | |
| 4147 | GSList *tags, *l; | |
| 4148 | GtkTextIter iter; | |
| 4149 | ||
| 4150 | if (mark != gtk_text_buffer_get_insert(buffer)) | |
| 4151 | return; | |
| 4152 | ||
| 4153 | if (!gtk_text_buffer_get_char_count(buffer)) | |
| 4154 | return; | |
| 4155 | ||
| 9924 | 4156 | 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
|
4157 | g_free(imhtml->edit.forecolor); |
| 8677 | 4158 | imhtml->edit.forecolor = NULL; |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
4159 | |
|
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
4160 | g_free(imhtml->edit.backcolor); |
| 8677 | 4161 | imhtml->edit.backcolor = NULL; |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
4162 | |
|
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
4163 | g_free(imhtml->edit.fontface); |
| 8677 | 4164 | imhtml->edit.fontface = NULL; |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
14010
diff
changeset
|
4165 | |
| 8677 | 4166 | imhtml->edit.fontsize = 0; |
| 4167 | imhtml->edit.link = NULL; | |
| 4168 | ||
| 4169 | gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); | |
| 4170 | ||
| 4171 | ||
| 4172 | if (gtk_text_iter_is_end(&iter)) | |
| 4173 | tags = gtk_text_iter_get_toggled_tags(&iter, FALSE); | |
| 4174 | else | |
| 4175 | tags = gtk_text_iter_get_tags(&iter); | |
| 4176 | ||
| 4177 | for (l = tags; l != NULL; l = l->next) { | |
| 4178 | GtkTextTag *tag = GTK_TEXT_TAG(l->data); | |
| 4179 | ||
| 4180 | if (tag->name) { | |
| 4181 | if (strcmp(tag->name, "BOLD") == 0) | |
| 4182 | imhtml->edit.bold = TRUE; | |
|
13138
4d3bd039da3e
[gaim-migrate @ 15499]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13137
diff
changeset
|
4183 | else if (strcmp(tag->name, "ITALICS") == 0) |
| 8677 | 4184 | imhtml->edit.italic = TRUE; |
|
13138
4d3bd039da3e
[gaim-migrate @ 15499]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13137
diff
changeset
|
4185 | else if (strcmp(tag->name, "UNDERLINE") == 0) |
| 8677 | 4186 | imhtml->edit.underline = TRUE; |
|
13138
4d3bd039da3e
[gaim-migrate @ 15499]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13137
diff
changeset
|
4187 | else if (strcmp(tag->name, "STRIKE") == 0) |
| 9924 | 4188 | imhtml->edit.strike = TRUE; |
|
13138
4d3bd039da3e
[gaim-migrate @ 15499]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13137
diff
changeset
|
4189 | else if (strncmp(tag->name, "FORECOLOR ", 10) == 0) |
| 8677 | 4190 | imhtml->edit.forecolor = g_strdup(&(tag->name)[10]); |
|
13138
4d3bd039da3e
[gaim-migrate @ 15499]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13137
diff
changeset
|
4191 | else if (strncmp(tag->name, "BACKCOLOR ", 10) == 0) |
| 8677 | 4192 | imhtml->edit.backcolor = g_strdup(&(tag->name)[10]); |
|
13138
4d3bd039da3e
[gaim-migrate @ 15499]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13137
diff
changeset
|
4193 | else if (strncmp(tag->name, "FONT FACE ", 10) == 0) |
| 8677 | 4194 | imhtml->edit.fontface = g_strdup(&(tag->name)[10]); |
|
13138
4d3bd039da3e
[gaim-migrate @ 15499]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13137
diff
changeset
|
4195 | else if (strncmp(tag->name, "FONT SIZE ", 10) == 0) |
| 8677 | 4196 | imhtml->edit.fontsize = strtol(&(tag->name)[10], NULL, 10); |
|
13138
4d3bd039da3e
[gaim-migrate @ 15499]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
13137
diff
changeset
|
4197 | else if ((strncmp(tag->name, "LINK ", 5) == 0) && !gtk_text_iter_is_end(&iter)) |
| 8677 | 4198 | imhtml->edit.link = tag; |
| 4199 | } | |
| 4200 | } | |
| 4201 | ||
| 4202 | g_slist_free(tags); | |
| 4203 | } | |
| 4204 | ||
|
12605
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4205 | static void imhtml_emit_signal_for_format(GtkIMHtml *imhtml, GtkIMHtmlButtons button) |
|
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4206 | { |
|
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4207 | GObject *object; |
|
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4208 | |
|
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4209 | g_return_if_fail(imhtml != NULL); |
|
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4210 | |
|
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4211 | object = g_object_ref(G_OBJECT(imhtml)); |
|
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4212 | g_signal_emit(object, signals[TOGGLE_FORMAT], 0, button); |
|
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4213 | g_object_unref(object); |
|
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4214 | } |
|
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4215 | |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4216 | static void imhtml_toggle_bold(GtkIMHtml *imhtml) |
| 8061 | 4217 | { |
| 8677 | 4218 | GtkTextIter start, end; |
| 4219 | ||
| 4220 | imhtml->edit.bold = !imhtml->edit.bold; | |
| 4221 | ||
| 4222 | if (imhtml->wbfo) { | |
| 4223 | gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 4224 | if (imhtml->edit.bold) | |
| 4225 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | |
| 4226 | else | |
| 4227 | 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
|
4228 | } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
| 8677 | 4229 | if (imhtml->edit.bold) |
| 4230 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | |
| 4231 | else | |
| 4232 | 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
|
4233 | |
| 8061 | 4234 | } |
| 4235 | } | |
| 4236 | ||
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4237 | void gtk_imhtml_toggle_bold(GtkIMHtml *imhtml) |
| 8061 | 4238 | { |
|
12605
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4239 | imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_BOLD); |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4240 | } |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4241 | |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4242 | static void imhtml_toggle_italic(GtkIMHtml *imhtml) |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4243 | { |
| 8677 | 4244 | GtkTextIter start, end; |
| 4245 | ||
| 4246 | imhtml->edit.italic = !imhtml->edit.italic; | |
| 4247 | ||
| 4248 | if (imhtml->wbfo) { | |
| 4249 | gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 4250 | if (imhtml->edit.italic) | |
| 4251 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); | |
| 4252 | else | |
| 4253 | 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
|
4254 | } 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
|
4255 | if (imhtml->edit.italic) |
| 8677 | 4256 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); |
| 4257 | else | |
| 4258 | gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); | |
| 8061 | 4259 | } |
| 4260 | } | |
| 4261 | ||
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4262 | void gtk_imhtml_toggle_italic(GtkIMHtml *imhtml) |
| 8061 | 4263 | { |
|
12605
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4264 | imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_ITALIC); |
|
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4265 | } |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4266 | |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4267 | static void imhtml_toggle_underline(GtkIMHtml *imhtml) |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4268 | { |
| 8677 | 4269 | GtkTextIter start, end; |
| 4270 | ||
| 4271 | imhtml->edit.underline = !imhtml->edit.underline; | |
| 4272 | ||
| 4273 | if (imhtml->wbfo) { | |
| 4274 | gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 4275 | if (imhtml->edit.underline) | |
| 4276 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); | |
| 4277 | else | |
| 4278 | 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
|
4279 | } 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
|
4280 | if (imhtml->edit.underline) |
| 8677 | 4281 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); |
| 4282 | else | |
| 4283 | gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); | |
| 8061 | 4284 | } |
| 4285 | } | |
| 4286 | ||
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4287 | void gtk_imhtml_toggle_underline(GtkIMHtml *imhtml) |
| 9924 | 4288 | { |
|
12605
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4289 | imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_UNDERLINE); |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4290 | } |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4291 | |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4292 | static void imhtml_toggle_strike(GtkIMHtml *imhtml) |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4293 | { |
| 9924 | 4294 | GtkTextIter start, end; |
| 4295 | ||
| 4296 | imhtml->edit.strike = !imhtml->edit.strike; | |
| 4297 | ||
| 4298 | if (imhtml->wbfo) { | |
| 4299 | gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 4300 | if (imhtml->edit.strike) | |
| 4301 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); | |
| 4302 | else | |
| 4303 | 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
|
4304 | } 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
|
4305 | if (imhtml->edit.strike) |
| 9924 | 4306 | gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); |
| 4307 | else | |
| 4308 | gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); | |
| 4309 | } | |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4310 | } |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4311 | |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4312 | void gtk_imhtml_toggle_strike(GtkIMHtml *imhtml) |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4313 | { |
|
12605
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4314 | imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_STRIKE); |
| 9924 | 4315 | } |
| 4316 | ||
| 8061 | 4317 | void gtk_imhtml_font_set_size(GtkIMHtml *imhtml, gint size) |
| 4318 | { | |
| 9025 | 4319 | GObject *object; |
| 8677 | 4320 | GtkTextIter start, end; |
| 8061 | 4321 | |
| 4322 | imhtml->edit.fontsize = size; | |
| 4323 | ||
| 8677 | 4324 | if (imhtml->wbfo) { |
| 4325 | gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 4326 | remove_font_size(imhtml, &start, &end, TRUE); | |
| 4327 | gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 4328 | find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
|
11276
aec923529d31
[gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents:
11275
diff
changeset
|
4329 | } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
| 8677 | 4330 | remove_font_size(imhtml, &start, &end, FALSE); |
| 4331 | gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 4332 | find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
| 8061 | 4333 | } |
| 8677 | 4334 | |
| 9025 | 4335 | object = g_object_ref(G_OBJECT(imhtml)); |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4336 | g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_SHRINK | GTK_IMHTML_GROW); |
| 9025 | 4337 | g_object_unref(object); |
| 8061 | 4338 | } |
| 4339 | ||
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4340 | static void imhtml_font_shrink(GtkIMHtml *imhtml) |
| 8061 | 4341 | { |
| 8677 | 4342 | GtkTextIter start, end; |
| 4343 | ||
| 8061 | 4344 | if (imhtml->edit.fontsize == 1) |
| 4345 | return; | |
| 4346 | ||
| 8677 | 4347 | if (!imhtml->edit.fontsize) |
| 4348 | imhtml->edit.fontsize = 2; | |
| 4349 | else | |
| 4350 | imhtml->edit.fontsize--; | |
| 4351 | ||
| 4352 | if (imhtml->wbfo) { | |
| 4353 | gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 4354 | remove_font_size(imhtml, &start, &end, TRUE); | |
| 4355 | gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 4356 | find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
|
11276
aec923529d31
[gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents:
11275
diff
changeset
|
4357 | } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
| 8677 | 4358 | remove_font_size(imhtml, &start, &end, FALSE); |
| 4359 | gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 4360 | find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
| 8061 | 4361 | } |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4362 | } |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4363 | |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4364 | void gtk_imhtml_font_shrink(GtkIMHtml *imhtml) |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4365 | { |
|
12605
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4366 | imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_SHRINK); |
| 8061 | 4367 | } |
| 4368 | ||
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4369 | static void imhtml_font_grow(GtkIMHtml *imhtml) |
| 8061 | 4370 | { |
| 8677 | 4371 | GtkTextIter start, end; |
| 4372 | ||
| 8061 | 4373 | if (imhtml->edit.fontsize == MAX_FONT_SIZE) |
| 4374 | return; | |
| 4375 | ||
| 8677 | 4376 | if (!imhtml->edit.fontsize) |
| 4377 | imhtml->edit.fontsize = 4; | |
| 4378 | else | |
| 4379 | imhtml->edit.fontsize++; | |
| 4380 | ||
| 4381 | if (imhtml->wbfo) { | |
| 4382 | gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 4383 | remove_font_size(imhtml, &start, &end, TRUE); | |
| 4384 | gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 4385 | find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
|
11276
aec923529d31
[gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents:
11275
diff
changeset
|
4386 | } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
| 8677 | 4387 | remove_font_size(imhtml, &start, &end, FALSE); |
| 4388 | gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 4389 | find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
| 8061 | 4390 | } |
|
11267
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4391 | } |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4392 | |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4393 | void gtk_imhtml_font_grow(GtkIMHtml *imhtml) |
|
78f1eb5b3d6e
[gaim-migrate @ 13449]
Richard Laager <rlaager@pidgin.im>
parents:
11240
diff
changeset
|
4394 | { |
|
12605
7390627a6aaf
[gaim-migrate @ 14940]
Richard Laager <rlaager@pidgin.im>
parents:
12600
diff
changeset
|
4395 | imhtml_emit_signal_for_format(imhtml, GTK_IMHTML_GROW); |
| 8061 | 4396 | } |
| 4397 | ||
|
13225
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4398 | 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
|
4399 | void (*remove_func)(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo), |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4400 | GtkTextTag *(find_func)(GtkIMHtml *imhtml, gchar *color), GtkIMHtmlButtons button) |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4401 | { |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4402 | GObject *object; |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4403 | GtkTextIter start; |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4404 | GtkTextIter end; |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4405 | |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4406 | g_free(*edit_field); |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4407 | *edit_field = NULL; |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4408 | |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4409 | if (value && strcmp(value, "") != 0) |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4410 | { |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4411 | *edit_field = g_strdup(value); |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4412 | |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4413 | if (imhtml->wbfo) |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4414 | { |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4415 | gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4416 | remove_func(imhtml, &start, &end, TRUE); |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4417 | gtk_text_buffer_apply_tag(imhtml->text_buffer, |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4418 | find_func(imhtml, *edit_field), &start, &end); |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4419 | } |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4420 | else |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4421 | { |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4422 | gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4423 | gtk_text_buffer_get_mark(imhtml->text_buffer, "insert")); |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4424 | 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
|
4425 | { |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4426 | remove_func(imhtml, &start, &end, FALSE); |
|
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, |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4429 | *edit_field), |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4430 | &start, &end); |
|
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 | } |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4433 | } |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4434 | else |
|
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 | if (imhtml->wbfo) |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4437 | { |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4438 | gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4439 | remove_func(imhtml, &start, &end, TRUE); |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4440 | } |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4441 | else |
|
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 | 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
|
4444 | remove_func(imhtml, &start, &end, TRUE); |
|
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 | } |
|
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 | object = g_object_ref(G_OBJECT(imhtml)); |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4449 | g_signal_emit(object, signals[TOGGLE_FORMAT], 0, button); |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4450 | g_object_unref(object); |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4451 | |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4452 | return *edit_field != NULL; |
| 10776 | 4453 | } |
| 4454 | ||
| 8061 | 4455 | gboolean gtk_imhtml_toggle_forecolor(GtkIMHtml *imhtml, const char *color) |
| 4456 | { | |
|
13225
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4457 | return gtk_imhtml_toggle_str_tag(imhtml, color, &imhtml->edit.forecolor, |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4458 | remove_font_forecolor, find_font_forecolor_tag, |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4459 | GTK_IMHTML_FORECOLOR); |
| 8061 | 4460 | } |
| 4461 | ||
| 4462 | gboolean gtk_imhtml_toggle_backcolor(GtkIMHtml *imhtml, const char *color) | |
| 4463 | { | |
|
13225
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4464 | return gtk_imhtml_toggle_str_tag(imhtml, color, &imhtml->edit.backcolor, |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4465 | remove_font_backcolor, find_font_backcolor_tag, |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4466 | GTK_IMHTML_BACKCOLOR); |
| 10776 | 4467 | } |
| 4468 | ||
| 4469 | gboolean gtk_imhtml_toggle_background(GtkIMHtml *imhtml, const char *color) | |
| 4470 | { | |
|
13225
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4471 | return gtk_imhtml_toggle_str_tag(imhtml, color, &imhtml->edit.background, |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4472 | remove_font_background, find_font_background_tag, |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4473 | GTK_IMHTML_BACKGROUND); |
| 8061 | 4474 | } |
| 4475 | ||
| 4476 | gboolean gtk_imhtml_toggle_fontface(GtkIMHtml *imhtml, const char *face) | |
| 4477 | { | |
|
13225
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4478 | return gtk_imhtml_toggle_str_tag(imhtml, face, &imhtml->edit.fontface, |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4479 | remove_font_face, find_font_face_tag, |
|
b82e04c17537
[gaim-migrate @ 15588]
Richard Laager <rlaager@pidgin.im>
parents:
13224
diff
changeset
|
4480 | GTK_IMHTML_FACE); |
| 8061 | 4481 | } |
| 4482 | ||
| 8677 | 4483 | void gtk_imhtml_toggle_link(GtkIMHtml *imhtml, const char *url) |
| 8061 | 4484 | { |
| 9025 | 4485 | GObject *object; |
| 8677 | 4486 | GtkTextIter start, end; |
| 4487 | GtkTextTag *linktag; | |
| 4488 | static guint linkno = 0; | |
| 4489 | gchar str[48]; | |
| 9007 | 4490 | GdkColor *color = NULL; |
| 8677 | 4491 | |
| 4492 | imhtml->edit.link = NULL; | |
| 4493 | ||
| 4494 | if (url) { | |
| 4495 | g_snprintf(str, sizeof(str), "LINK %d", linkno++); | |
| 4496 | str[47] = '\0'; | |
| 4497 | ||
| 9007 | 4498 | gtk_widget_style_get(GTK_WIDGET(imhtml), "hyperlink-color", &color, NULL); |
| 9008 | 4499 | if (color) { |
| 9007 | 4500 | imhtml->edit.link = linktag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground-gdk", color, "underline", PANGO_UNDERLINE_SINGLE, NULL); |
| 9008 | 4501 | gdk_color_free(color); |
| 4502 | } else { | |
| 9007 | 4503 | imhtml->edit.link = linktag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL); |
| 9008 | 4504 | } |
| 8677 | 4505 | g_object_set_data_full(G_OBJECT(linktag), "link_url", g_strdup(url), g_free); |
| 4506 | g_signal_connect(G_OBJECT(linktag), "event", G_CALLBACK(tag_event), NULL); | |
| 4507 | ||
|
11276
aec923529d31
[gaim-migrate @ 13463]
Richard Laager <rlaager@pidgin.im>
parents:
11275
diff
changeset
|
4508 | if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { |
| 8677 | 4509 | remove_font_link(imhtml, &start, &end, FALSE); |
| 4510 | gtk_text_buffer_apply_tag(imhtml->text_buffer, linktag, &start, &end); | |
| 4511 | } | |
| 4512 | } | |
| 9025 | 4513 | |
| 4514 | object = g_object_ref(G_OBJECT(imhtml)); | |
| 4515 | g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_LINK); | |
| 4516 | g_object_unref(object); | |
| 8677 | 4517 | } |
| 4518 | ||
| 4519 | void gtk_imhtml_insert_link(GtkIMHtml *imhtml, GtkTextMark *mark, const char *url, const char *text) | |
| 4520 | { | |
| 8061 | 4521 | GtkTextIter iter; |
| 8677 | 4522 | |
| 9599 | 4523 | if (gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) |
| 4524 | gtk_text_buffer_delete_selection(imhtml->text_buffer, TRUE, TRUE); | |
| 4525 | ||
| 8677 | 4526 | gtk_imhtml_toggle_link(imhtml, url); |
| 8061 | 4527 | gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); |
| 8677 | 4528 | gtk_text_buffer_insert(imhtml->text_buffer, &iter, text, -1); |
| 4529 | gtk_imhtml_toggle_link(imhtml, NULL); | |
| 8061 | 4530 | } |
| 4531 | ||
| 4532 | void gtk_imhtml_insert_smiley(GtkIMHtml *imhtml, const char *sml, char *smiley) | |
| 4533 | { | |
| 8677 | 4534 | GtkTextMark *mark; |
| 8061 | 4535 | GtkTextIter iter; |
| 8677 | 4536 | |
|
11750
63f951281392
[gaim-migrate @ 14041]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11701
diff
changeset
|
4537 | 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
|
4538 | gtk_text_buffer_delete_selection(imhtml->text_buffer, TRUE, TRUE); |
|
63f951281392
[gaim-migrate @ 14041]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11701
diff
changeset
|
4539 | |
| 8677 | 4540 | mark = gtk_text_buffer_get_insert(imhtml->text_buffer); |
| 4541 | ||
| 4542 | gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); | |
| 4543 | gtk_imhtml_insert_smiley_at_iter(imhtml, sml, smiley, &iter); | |
| 4544 | } | |
| 4545 | ||
| 13552 | 4546 | static gboolean |
| 4547 | image_expose(GtkWidget *widget, GdkEventExpose *event, gpointer user_data) | |
| 4548 | { | |
| 4549 | GTK_WIDGET_CLASS(GTK_WIDGET_GET_CLASS(widget))->expose_event(widget, event); | |
| 4550 | ||
| 4551 | return TRUE; | |
| 4552 | } | |
| 4553 | ||
|
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
|
4554 | /* 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
|
4555 | 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
|
4556 | { |
|
aa5b9456e258
Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents:
16291
diff
changeset
|
4557 | 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
|
4558 | 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
|
4559 | 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
|
4560 | 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
|
4561 | 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
|
4562 | 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
|
4563 | 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
|
4564 | 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
|
4565 | } |
|
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 | 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
|
4567 | } |
|
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 | } |
|
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 | |
| 8677 | 4570 | void gtk_imhtml_insert_smiley_at_iter(GtkIMHtml *imhtml, const char *sml, char *smiley, GtkTextIter *iter) |
| 4571 | { | |
| 8061 | 4572 | GdkPixbuf *pixbuf = NULL; |
| 4573 | GdkPixbufAnimation *annipixbuf = NULL; | |
| 4574 | 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
|
4575 | GtkTextChildAnchor *anchor = NULL; |
| 15884 | 4576 | char *unescaped = purple_unescape_html(smiley); |
|
11525
1d06283bdcc9
[gaim-migrate @ 13773]
Francesco Fracassi <ffracassi@users.sourceforge.net>
parents:
11485
diff
changeset
|
4577 | 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
|
4578 | GtkWidget *ebox = NULL; |
| 8061 | 4579 | |
| 10526 | 4580 | if (imhtml->format_functions & GTK_IMHTML_SMILEY) { |
|
10522
d505522bcc93
[gaim-migrate @ 11838]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10504
diff
changeset
|
4581 | annipixbuf = gtk_smiley_tree_image(imhtml, sml, unescaped); |
| 10526 | 4582 | if (annipixbuf) { |
| 4583 | if (gdk_pixbuf_animation_is_static_image(annipixbuf)) { | |
|
10522
d505522bcc93
[gaim-migrate @ 11838]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10504
diff
changeset
|
4584 | pixbuf = gdk_pixbuf_animation_get_static_image(annipixbuf); |
| 10526 | 4585 | if (pixbuf) |
|
10522
d505522bcc93
[gaim-migrate @ 11838]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10504
diff
changeset
|
4586 | icon = gtk_image_new_from_pixbuf(pixbuf); |
|
d505522bcc93
[gaim-migrate @ 11838]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10504
diff
changeset
|
4587 | } else { |
|
d505522bcc93
[gaim-migrate @ 11838]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10504
diff
changeset
|
4588 | 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
|
4589 | 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
|
4590 | 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
|
4591 | 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
|
4592 | 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
|
4593 | 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
|
4594 | 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
|
4595 | 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
|
4596 | } |
|
aa5b9456e258
Fixes #213 This allows only 20 animated smileys to be animnating at a time
Sean Egan <seanegan@pidgin.im>
parents:
16291
diff
changeset
|
4597 | } 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
|
4598 | 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
|
4599 | } |
|
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 | 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
|
4601 | g_queue_push_tail(imhtml->animations, icon); |
|
10522
d505522bcc93
[gaim-migrate @ 11838]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10504
diff
changeset
|
4602 | } |
| 8061 | 4603 | } |
| 4604 | } | |
| 4605 | ||
|
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
|
4606 | 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
|
4607 | ebox = gtk_event_box_new(); |
| 17406 | 4608 | #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
|
4609 | gtk_event_box_set_visible_window(GTK_EVENT_BOX(ebox), FALSE); |
| 17406 | 4610 | #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
|
4611 | 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
|
4612 | } |
|
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
|
4613 | |
| 8061 | 4614 | if (icon) { |
| 8890 | 4615 | anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); |
| 4616 | g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_plaintext", g_strdup(unescaped), g_free); | |
| 4617 | g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_htmltext", g_strdup(smiley), g_free); | |
| 4618 | ||
| 13552 | 4619 | /* This catches the expose events generated by animated |
| 4620 | * images, and ensures that they are handled by the image | |
| 4621 | * itself, without propagating to the textview and causing | |
| 4622 | * a complete refresh */ | |
| 4623 | g_signal_connect(G_OBJECT(icon), "expose-event", G_CALLBACK(image_expose), NULL); | |
| 4624 | ||
| 8061 | 4625 | 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
|
4626 | 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
|
4627 | 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
|
4628 | 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
|
4629 | } 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
|
4630 | 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
|
4631 | 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
|
4632 | 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
|
4633 | 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
|
4634 | 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
|
4635 | gtk_widget_show(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
|
4636 | 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
|
4637 | } |
| 8890 | 4638 | } else { |
| 4639 | gtk_text_buffer_insert(imhtml->text_buffer, iter, smiley, -1); | |
| 8061 | 4640 | } |
| 8890 | 4641 | |
|
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 | 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
|
4644 | } |
|
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 | |
| 8890 | 4646 | g_free(unescaped); |
| 8061 | 4647 | } |
| 4648 | ||
| 8962 | 4649 | void gtk_imhtml_insert_image_at_iter(GtkIMHtml *imhtml, int id, GtkTextIter *iter) |
| 4650 | { | |
|
18151
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
4651 | GdkPixbufAnimation *anim = NULL; |
| 8962 | 4652 | const char *filename = NULL; |
| 4653 | gpointer image; | |
| 4654 | GdkRectangle rect; | |
| 4655 | GtkIMHtmlScalable *scalable = NULL; | |
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
4656 | struct scalable_data *sd; |
| 8962 | 4657 | int minus; |
| 4658 | ||
| 4659 | if (!imhtml->funcs || !imhtml->funcs->image_get || | |
| 4660 | !imhtml->funcs->image_get_size || !imhtml->funcs->image_get_data || | |
| 4661 | !imhtml->funcs->image_get_filename || !imhtml->funcs->image_ref || | |
| 4662 | !imhtml->funcs->image_unref) | |
| 4663 | return; | |
| 4664 | ||
| 4665 | image = imhtml->funcs->image_get(id); | |
| 4666 | ||
| 4667 | if (image) { | |
| 4668 | gpointer data; | |
| 4669 | size_t len; | |
| 4670 | ||
| 4671 | data = imhtml->funcs->image_get_data(image); | |
| 4672 | len = imhtml->funcs->image_get_size(image); | |
| 4673 | ||
| 4674 | if (data && len) { | |
| 4675 | GdkPixbufLoader *loader = gdk_pixbuf_loader_new(); | |
| 4676 | gdk_pixbuf_loader_write(loader, data, len, NULL); | |
|
12230
2f327bccf63b
[gaim-migrate @ 14532]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12229
diff
changeset
|
4677 | 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
|
4678 | 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
|
4679 | if (anim) |
|
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
4680 | g_object_ref(G_OBJECT(anim)); |
| 9337 | 4681 | g_object_unref(G_OBJECT(loader)); |
| 8962 | 4682 | } |
| 4683 | ||
| 4684 | } | |
| 4685 | ||
|
18151
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
4686 | if (anim) { |
|
11299
06bb44ed0cf3
[gaim-migrate @ 13499]
Richard Laager <rlaager@pidgin.im>
parents:
11276
diff
changeset
|
4687 | struct im_image_data *t = g_new(struct im_image_data, 1); |
| 8962 | 4688 | filename = imhtml->funcs->image_get_filename(image); |
| 4689 | imhtml->funcs->image_ref(id); | |
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
4690 | t->id = id; |
|
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
4691 | 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
|
4692 | 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
|
4693 | 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
|
4694 | g_object_unref(G_OBJECT(anim)); |
| 8962 | 4695 | } else { |
|
18151
97fd60f47229
When an animated image is inserted into a conversation window, animate
Mark Doliner <markdoliner@pidgin.im>
parents:
18119
diff
changeset
|
4696 | GdkPixbuf *pixbuf; |
| 8962 | 4697 | pixbuf = gtk_widget_render_icon(GTK_WIDGET(imhtml), GTK_STOCK_MISSING_IMAGE, |
| 4698 | 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
|
4699 | 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
|
4700 | g_object_unref(G_OBJECT(pixbuf)); |
| 8962 | 4701 | } |
| 4702 | ||
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
4703 | 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
|
4704 | sd->scalable = scalable; |
|
11233
28c0f184a2d4
[gaim-migrate @ 13373]
Daniel Atallah <datallah@pidgin.im>
parents:
11224
diff
changeset
|
4705 | sd->mark = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, iter, TRUE); |
| 8962 | 4706 | gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); |
| 4707 | scalable->add_to(scalable, imhtml, iter); | |
| 4708 | minus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(imhtml)) + | |
| 4709 | gtk_text_view_get_right_margin(GTK_TEXT_VIEW(imhtml)); | |
| 4710 | scalable->scale(scalable, rect.width - minus, rect.height); | |
|
11224
04c1712bb953
[gaim-migrate @ 13360]
Daniel Atallah <datallah@pidgin.im>
parents:
11143
diff
changeset
|
4711 | imhtml->scalables = g_list_append(imhtml->scalables, sd); |
| 8962 | 4712 | } |
| 4713 | ||
| 8677 | 4714 | static const gchar *tag_to_html_start(GtkTextTag *tag) |
| 8061 | 4715 | { |
| 8677 | 4716 | const gchar *name; |
| 4717 | static gchar buf[1024]; | |
| 4718 | ||
| 4719 | name = tag->name; | |
| 4720 | g_return_val_if_fail(name != NULL, ""); | |
| 4721 | ||
| 4722 | if (strcmp(name, "BOLD") == 0) { | |
| 4723 | return "<b>"; | |
| 4724 | } else if (strcmp(name, "ITALICS") == 0) { | |
| 4725 | return "<i>"; | |
| 4726 | } else if (strcmp(name, "UNDERLINE") == 0) { | |
| 4727 | return "<u>"; | |
| 9924 | 4728 | } else if (strcmp(name, "STRIKE") == 0) { |
| 4729 | return "<s>"; | |
| 8677 | 4730 | } else if (strncmp(name, "LINK ", 5) == 0) { |
| 4731 | char *tmp = g_object_get_data(G_OBJECT(tag), "link_url"); | |
| 4732 | if (tmp) { | |
| 4733 | g_snprintf(buf, sizeof(buf), "<a href=\"%s\">", tmp); | |
| 4734 | buf[sizeof(buf)-1] = '\0'; | |
| 4735 | return buf; | |
| 4736 | } else { | |
| 4737 | return ""; | |
| 4738 | } | |
| 4739 | } else if (strncmp(name, "FORECOLOR ", 10) == 0) { | |
| 4740 | g_snprintf(buf, sizeof(buf), "<font color=\"%s\">", &name[10]); | |
| 4741 | return buf; | |
| 4742 | } else if (strncmp(name, "BACKCOLOR ", 10) == 0) { | |
| 4743 | g_snprintf(buf, sizeof(buf), "<font back=\"%s\">", &name[10]); | |
| 4744 | return buf; | |
| 10776 | 4745 | } else if (strncmp(name, "BACKGROUND ", 10) == 0) { |
| 4746 | g_snprintf(buf, sizeof(buf), "<body bgcolor=\"%s\">", &name[11]); | |
| 4747 | return buf; | |
| 8677 | 4748 | } else if (strncmp(name, "FONT FACE ", 10) == 0) { |
| 4749 | g_snprintf(buf, sizeof(buf), "<font face=\"%s\">", &name[10]); | |
| 4750 | return buf; | |
| 4751 | } else if (strncmp(name, "FONT SIZE ", 10) == 0) { | |
| 4752 | g_snprintf(buf, sizeof(buf), "<font size=\"%s\">", &name[10]); | |
| 4753 | return buf; | |
| 4754 | } else { | |
| 4755 | return ""; | |
| 4756 | } | |
| 8061 | 4757 | } |
| 4758 | ||
| 8677 | 4759 | static const gchar *tag_to_html_end(GtkTextTag *tag) |
| 8061 | 4760 | { |
| 8677 | 4761 | const gchar *name; |
| 4762 | ||
| 4763 | name = tag->name; | |
| 4764 | g_return_val_if_fail(name != NULL, ""); | |
| 4765 | ||
| 4766 | if (strcmp(name, "BOLD") == 0) { | |
| 4767 | return "</b>"; | |
| 4768 | } else if (strcmp(name, "ITALICS") == 0) { | |
| 4769 | return "</i>"; | |
| 4770 | } else if (strcmp(name, "UNDERLINE") == 0) { | |
| 4771 | return "</u>"; | |
| 9924 | 4772 | } else if (strcmp(name, "STRIKE") == 0) { |
| 4773 | return "</s>"; | |
| 8677 | 4774 | } else if (strncmp(name, "LINK ", 5) == 0) { |
| 4775 | return "</a>"; | |
| 4776 | } else if (strncmp(name, "FORECOLOR ", 10) == 0) { | |
| 4777 | return "</font>"; | |
| 4778 | } else if (strncmp(name, "BACKCOLOR ", 10) == 0) { | |
| 4779 | return "</font>"; | |
| 10776 | 4780 | } else if (strncmp(name, "BACKGROUND ", 10) == 0) { |
| 4781 | return "</body>"; | |
| 8677 | 4782 | } else if (strncmp(name, "FONT FACE ", 10) == 0) { |
| 4783 | return "</font>"; | |
| 4784 | } else if (strncmp(name, "FONT SIZE ", 10) == 0) { | |
| 4785 | return "</font>"; | |
| 4786 | } else { | |
| 4787 | return ""; | |
| 4788 | } | |
| 4789 | } | |
| 4790 | ||
| 4791 | static gboolean tag_ends_here(GtkTextTag *tag, GtkTextIter *iter, GtkTextIter *niter) | |
| 4792 | { | |
| 4793 | return ((gtk_text_iter_has_tag(iter, GTK_TEXT_TAG(tag)) && | |
| 4794 | !gtk_text_iter_has_tag(niter, GTK_TEXT_TAG(tag))) || | |
| 4795 | gtk_text_iter_is_end(niter)); | |
| 8061 | 4796 | } |
| 4797 | ||
| 4798 | /* Basic notion here: traverse through the text buffer one-by-one, non-character elements, such | |
| 4799 | * as smileys and IM images are represented by the Unicode "unknown" character. Handle them. Else | |
| 8677 | 4800 | * check for tags that are toggled on, insert their html form, and push them on the queue. Then insert |
| 4801 | * 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
|
4802 | * Finally, replace <, >, &, and " with their HTML equivalent. |
| 8677 | 4803 | */ |
| 8061 | 4804 | char *gtk_imhtml_get_markup_range(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) |
| 4805 | { | |
| 4806 | gunichar c; | |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4807 | GtkTextIter iter, next_iter, non_neutral_iter; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4808 | gboolean is_rtl_message = FALSE; |
| 8061 | 4809 | GString *str = g_string_new(""); |
| 8677 | 4810 | GSList *tags, *sl; |
| 4811 | GQueue *q, *r; | |
| 4812 | GtkTextTag *tag; | |
| 4813 | ||
| 4814 | q = g_queue_new(); | |
| 4815 | r = g_queue_new(); | |
| 4816 | ||
| 8061 | 4817 | |
| 4818 | gtk_text_iter_order(start, end); | |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4819 | non_neutral_iter = next_iter = iter = *start; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4820 | gtk_text_iter_forward_char(&next_iter); |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4821 | |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4822 | /* Bi-directional text support */ |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4823 | /* 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
|
4824 | #ifdef HAVE_PANGO14 |
| 16144 | 4825 | 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
|
4826 | && gtk_text_iter_forward_char(&non_neutral_iter)); |
| 16144 | 4827 | 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
|
4828 | is_rtl_message = TRUE; |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4829 | 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
|
4830 | } |
|
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
|
4831 | #endif |
| 8677 | 4832 | |
| 9071 | 4833 | /* First add the tags that are already in progress (we don't care about non-printing tags)*/ |
| 8677 | 4834 | tags = gtk_text_iter_get_tags(start); |
| 4835 | ||
| 4836 | for (sl = tags; sl; sl = sl->next) { | |
| 4837 | tag = sl->data; | |
| 4838 | if (!gtk_text_iter_toggles_tag(start, GTK_TEXT_TAG(tag))) { | |
| 9071 | 4839 | if (strlen(tag_to_html_end(tag)) > 0) |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
4840 | g_string_append(str, tag_to_html_start(tag)); |
| 8677 | 4841 | g_queue_push_tail(q, tag); |
| 8061 | 4842 | } |
| 4843 | } | |
| 8677 | 4844 | g_slist_free(tags); |
| 8061 | 4845 | |
| 4846 | while ((c = gtk_text_iter_get_char(&iter)) != 0 && !gtk_text_iter_equal(&iter, end)) { | |
| 8677 | 4847 | |
| 4848 | tags = gtk_text_iter_get_tags(&iter); | |
| 4849 | ||
| 4850 | for (sl = tags; sl; sl = sl->next) { | |
| 4851 | tag = sl->data; | |
| 4852 | if (gtk_text_iter_begins_tag(&iter, GTK_TEXT_TAG(tag))) { | |
| 9071 | 4853 | if (strlen(tag_to_html_end(tag)) > 0) |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
4854 | g_string_append(str, tag_to_html_start(tag)); |
| 8677 | 4855 | g_queue_push_tail(q, tag); |
| 4856 | } | |
| 4857 | } | |
| 4858 | ||
| 4859 | ||
| 8061 | 4860 | if (c == 0xFFFC) { |
| 4861 | GtkTextChildAnchor* anchor = gtk_text_iter_get_child_anchor(&iter); | |
| 9071 | 4862 | if (anchor) { |
| 4863 | char *text = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_htmltext"); | |
| 4864 | if (text) | |
| 4865 | str = g_string_append(str, text); | |
| 4866 | } | |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
4867 | } else if (c == '<') { |
| 8677 | 4868 | str = g_string_append(str, "<"); |
| 4869 | } else if (c == '>') { | |
| 4870 | str = g_string_append(str, ">"); | |
| 4871 | } else if (c == '&') { | |
| 4872 | str = g_string_append(str, "&"); | |
| 4873 | } else if (c == '"') { | |
| 4874 | str = g_string_append(str, """); | |
| 4875 | } else if (c == '\n') { | |
| 4876 | str = g_string_append(str, "<br>"); | |
| 8061 | 4877 | } else { |
| 8677 | 4878 | str = g_string_append_unichar(str, c); |
| 4879 | } | |
| 4880 | ||
| 4881 | tags = g_slist_reverse(tags); | |
| 4882 | for (sl = tags; sl; sl = sl->next) { | |
| 4883 | tag = sl->data; | |
| 9071 | 4884 | /** 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
|
4885 | if (tag_ends_here(tag, &iter, &next_iter) && strlen(tag_to_html_end(tag)) > 0) { |
| 8677 | 4886 | |
| 4887 | GtkTextTag *tmp; | |
| 4888 | ||
| 4889 | while ((tmp = g_queue_pop_tail(q)) != tag) { | |
| 4890 | if (tmp == NULL) | |
| 4891 | break; | |
| 4892 | ||
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4893 | if (!tag_ends_here(tmp, &iter, &next_iter) && strlen(tag_to_html_end(tmp)) > 0) |
| 8677 | 4894 | g_queue_push_tail(r, tmp); |
|
11572
3aaac95fa1ec
[gaim-migrate @ 13840]
Daniel Atallah <datallah@pidgin.im>
parents:
11525
diff
changeset
|
4895 | g_string_append(str, tag_to_html_end(GTK_TEXT_TAG(tmp))); |
| 8677 | 4896 | } |
| 4897 | ||
| 4898 | if (tmp == NULL) | |
| 15884 | 4899 | 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
|
4900 | else |
| 8677 | 4901 | g_string_append(str, tag_to_html_end(GTK_TEXT_TAG(tag))); |
| 4902 | ||
| 4903 | while ((tmp = g_queue_pop_head(r))) { | |
| 4904 | g_string_append(str, tag_to_html_start(GTK_TEXT_TAG(tmp))); | |
| 4905 | g_queue_push_tail(q, tmp); | |
| 8061 | 4906 | } |
| 4907 | } | |
| 4908 | } | |
| 8677 | 4909 | |
| 4910 | g_slist_free(tags); | |
| 8061 | 4911 | gtk_text_iter_forward_char(&iter); |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4912 | gtk_text_iter_forward_char(&next_iter); |
| 8061 | 4913 | } |
| 8677 | 4914 | |
| 4915 | while ((tag = g_queue_pop_tail(q))) | |
| 4916 | g_string_append(str, tag_to_html_end(GTK_TEXT_TAG(tag))); | |
| 4917 | ||
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4918 | /* Bi-directional text support - close tags */ |
| 16144 | 4919 | if (is_rtl_message) |
|
16143
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4920 | g_string_append(str, "</SPAN>"); |
|
6393e5b11ff5
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
15931
diff
changeset
|
4921 | |
| 8677 | 4922 | g_queue_free(q); |
| 4923 | g_queue_free(r); | |
| 8061 | 4924 | return g_string_free(str, FALSE); |
| 4925 | } | |
| 4926 | ||
| 8698 | 4927 | void gtk_imhtml_close_tags(GtkIMHtml *imhtml, GtkTextIter *iter) |
| 8061 | 4928 | { |
| 4929 | if (imhtml->edit.bold) | |
| 4930 | gtk_imhtml_toggle_bold(imhtml); | |
| 4931 | ||
| 4932 | if (imhtml->edit.italic) | |
| 4933 | gtk_imhtml_toggle_italic(imhtml); | |
| 4934 | ||
| 4935 | if (imhtml->edit.underline) | |
| 4936 | gtk_imhtml_toggle_underline(imhtml); | |
| 4937 | ||
| 9924 | 4938 | if (imhtml->edit.strike) |
| 4939 | gtk_imhtml_toggle_strike(imhtml); | |
| 4940 | ||
| 8061 | 4941 | if (imhtml->edit.forecolor) |
| 4942 | gtk_imhtml_toggle_forecolor(imhtml, NULL); | |
| 4943 | ||
| 4944 | if (imhtml->edit.backcolor) | |
| 4945 | gtk_imhtml_toggle_backcolor(imhtml, NULL); | |
| 4946 | ||
| 4947 | if (imhtml->edit.fontface) | |
| 4948 | gtk_imhtml_toggle_fontface(imhtml, NULL); | |
| 4949 | ||
| 8677 | 4950 | imhtml->edit.fontsize = 0; |
| 4951 | ||
| 8719 | 4952 | if (imhtml->edit.link) |
| 4953 | gtk_imhtml_toggle_link(imhtml, NULL); | |
| 4954 | ||
| 8698 | 4955 | gtk_text_buffer_remove_all_tags(imhtml->text_buffer, iter, iter); |
| 8061 | 4956 | |
| 4957 | } | |
| 4958 | ||
| 4959 | char *gtk_imhtml_get_markup(GtkIMHtml *imhtml) | |
| 4960 | { | |
| 4961 | GtkTextIter start, end; | |
| 4962 | ||
| 4963 | gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); | |
| 4964 | gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
| 4965 | return gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
| 4966 | } | |
| 4967 | ||
| 8677 | 4968 | char **gtk_imhtml_get_markup_lines(GtkIMHtml *imhtml) |
| 4969 | { | |
| 4970 | int i, j, lines; | |
| 4971 | GtkTextIter start, end; | |
| 4972 | char **ret; | |
| 4973 | ||
| 4974 | lines = gtk_text_buffer_get_line_count(imhtml->text_buffer); | |
| 4975 | ret = g_new0(char *, lines + 1); | |
| 4976 | gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); | |
| 4977 | end = start; | |
| 4978 | gtk_text_iter_forward_to_line_end(&end); | |
| 4979 | ||
| 4980 | for (i = 0, j = 0; i < lines; i++) { | |
| 9612 | 4981 | if (gtk_text_iter_get_char(&start) != '\n') { |
| 4982 | ret[j] = gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
| 4983 | if (ret[j] != NULL) | |
| 4984 | j++; | |
| 4985 | } | |
| 4986 | ||
| 8677 | 4987 | gtk_text_iter_forward_line(&start); |
| 4988 | end = start; | |
| 4989 | gtk_text_iter_forward_to_line_end(&end); | |
| 4990 | } | |
| 4991 | ||
| 4992 | return ret; | |
| 4993 | } | |
| 4994 | ||
| 4995 | char *gtk_imhtml_get_text(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *stop) | |
| 8061 | 4996 | { |
| 8519 | 4997 | GString *str = g_string_new(""); |
| 4998 | GtkTextIter iter, end; | |
| 4999 | gunichar c; | |
| 5000 | ||
| 8677 | 5001 | if (start == NULL) |
| 5002 | gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter); | |
| 5003 | else | |
| 5004 | iter = *start; | |
| 5005 | ||
| 5006 | if (stop == NULL) | |
| 5007 | gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
| 5008 | else | |
| 5009 | end = *stop; | |
| 5010 | ||
| 5011 | gtk_text_iter_order(&iter, &end); | |
| 8519 | 5012 | |
| 5013 | while ((c = gtk_text_iter_get_char(&iter)) != 0 && !gtk_text_iter_equal(&iter, &end)) { | |
| 5014 | if (c == 0xFFFC) { | |
| 8677 | 5015 | GtkTextChildAnchor* anchor; |
| 5016 | char *text = NULL; | |
| 5017 | ||
| 5018 | anchor = gtk_text_iter_get_child_anchor(&iter); | |
| 5019 | if (anchor) | |
| 8698 | 5020 | text = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_plaintext"); |
| 8677 | 5021 | if (text) |
| 5022 | str = g_string_append(str, text); | |
| 8519 | 5023 | } else { |
| 5024 | g_string_append_unichar(str, c); | |
| 5025 | } | |
| 5026 | gtk_text_iter_forward_char(&iter); | |
| 5027 | } | |
| 5028 | ||
| 5029 | return g_string_free(str, FALSE); | |
| 8061 | 5030 | } |
| 8962 | 5031 | |
| 5032 | void gtk_imhtml_set_funcs(GtkIMHtml *imhtml, GtkIMHtmlFuncs *f) | |
| 5033 | { | |
| 5034 | g_return_if_fail(imhtml != NULL); | |
| 5035 | imhtml->funcs = f; | |
| 5036 | } | |
|
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
|
5037 | |
|
8be39f0de528
Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17288
diff
changeset
|
5038 | 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
|
5039 | { |
|
18240
0a7d2fde749b
Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
18185
diff
changeset
|
5040 | 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
|
5041 | |
|
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
|
5042 | 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
|
5043 | 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
|
5044 | 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
|
5045 | |
|
18240
0a7d2fde749b
Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
18185
diff
changeset
|
5046 | 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
|
5047 | |
|
0a7d2fde749b
Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
18185
diff
changeset
|
5048 | 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
|
5049 | 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
|
5050 | 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
|
5051 | { |
|
0a7d2fde749b
Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
18185
diff
changeset
|
5052 | 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
|
5053 | 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
|
5054 | } |
|
0a7d2fde749b
Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
18185
diff
changeset
|
5055 | 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
|
5056 | 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
|
5057 | |
|
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
|
5058 | 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
|
5059 | 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
|
5060 | 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
|
5061 | |
|
8be39f0de528
Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17288
diff
changeset
|
5062 | 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
|
5063 | 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
|
5064 | |
|
8be39f0de528
Allow formatted text in the pounce dialog. Also, use the same code to
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17288
diff
changeset
|
5065 | 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
|
5066 | 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
|
5067 | |
|
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_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
|
5069 | 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
|
5070 | |
|
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 | 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
|
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 | 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
|
5074 | |
|
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 | /* 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
|
5076 | 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
|
5077 | 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
|
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 | |
|
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 | 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
|
5081 | { |
|
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 | 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
|
5083 | &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
|
5084 | 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
|
5085 | 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
|
5086 | 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
|
5087 | 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
|
5088 | } 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
|
5089 | 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
|
5090 | |
|
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 | 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
|
5092 | |
|
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 | 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
|
5094 | 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
|
5095 | { |
|
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 | 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
|
5097 | &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
|
5098 | 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
|
5099 | 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
|
5100 | 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
|
5101 | 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
|
5102 | } 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
|
5103 | 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
|
5104 | |
|
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 | 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
|
5106 | |
|
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 | 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
|
5108 | 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
|
5109 | 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
|
5110 | 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
|
5111 | } 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
|
5112 | 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
|
5113 | 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
|
5114 | } |
|
18240
0a7d2fde749b
Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
18185
diff
changeset
|
5115 | |
|
0a7d2fde749b
Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
18185
diff
changeset
|
5116 | 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
|
5117 | 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
|
5118 | |
|
0a7d2fde749b
Fix setting the sensitivity of the toolbar items in a number of places
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
18185
diff
changeset
|
5119 | 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
|
5120 | } |
|
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 | |
|
18105
bab0b0bcb664
propagate from branch 'im.pidgin.pidgin' (head 1b4384bff09a39fca58692fb6c929d4fe1276022)
Sadrul Habib Chowdhury <sadrul@pidgin.im>
diff
changeset
|
5122 |