Mercurial > pidgin.yaz
annotate src/gtkimhtmltoolbar.c @ 10134:0aca774bef87
[gaim-migrate @ 11198]
Patch 1051145, from Nathan Fredrickson, a rewrite of the smiley selection
dialog:
This patch replaces the smiely selection dialog with a
smiley popup menu. The smileys are still arranged in a
square grid.
Screenshots here:
http://worksintheory.org/files/gaim/smiley-menu/
One outstanding issue is with the yahoo smileys. Some
of them are extra wide, and it seems that pixmap width
affects menuitem height due to gtk's calculation of the
"toggle size". The result is unecesseary vertical
spacing. Not sure whether this is a gtk bug or not.
Even with the extra vertical spacing, which only
effects yahoo smiley's, I prefer this menu to the
original dialog.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sat, 23 Oct 2004 18:07:11 +0000 |
parents | ee50e4797352 |
children | 3855d3467437 |
rev | line source |
---|---|
8317 | 1 /* |
2 * GtkIMHtmlToolbar | |
3 * | |
4 * Gaim is the legal property of its developers, whose names are too numerous | |
5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
6 * source distribution. | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 * | |
22 */ | |
9791 | 23 #include "internal.h" |
24 #include "gtkgaim.h" | |
8317 | 25 |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
26 #include "imgstore.h" |
8317 | 27 #include "notify.h" |
28 #include "request.h" | |
29 #include "stock.h" | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
30 #include "util.h" |
8317 | 31 |
9730 | 32 #include "gtkdialogs.h" |
33 #include "gtkimhtmltoolbar.h" | |
34 #include "gtkutils.h" | |
35 | |
10080 | 36 static GtkHBoxClass *parent_class = NULL; |
8317 | 37 |
38 static void do_bold(GtkWidget *bold, GtkIMHtmlToolbar *toolbar) | |
39 { | |
8481 | 40 GObject *object; |
10134 | 41 |
8317 | 42 g_return_if_fail(toolbar); |
10134 | 43 |
8481 | 44 /* block the format_function_toggle handler */ |
45 object = g_object_ref(G_OBJECT(GTK_IMHTML(toolbar->imhtml))); | |
46 g_signal_handlers_block_matched(object, G_SIGNAL_MATCH_DATA, 0, 0, NULL, | |
47 NULL, toolbar); | |
8317 | 48 gtk_imhtml_toggle_bold(GTK_IMHTML(toolbar->imhtml)); |
8481 | 49 g_signal_handlers_unblock_matched(object, G_SIGNAL_MATCH_DATA, 0, 0, NULL, |
50 NULL, toolbar); | |
51 g_object_unref(object); | |
10134 | 52 |
8317 | 53 gtk_widget_grab_focus(toolbar->imhtml); |
54 } | |
55 | |
56 static void | |
57 do_italic(GtkWidget *italic, GtkIMHtmlToolbar *toolbar) | |
58 { | |
8481 | 59 GObject *object; |
10134 | 60 |
8317 | 61 g_return_if_fail(toolbar); |
10134 | 62 |
8481 | 63 /* block the format_function_toggle handler */ |
64 object = g_object_ref(G_OBJECT(GTK_IMHTML(toolbar->imhtml))); | |
65 g_signal_handlers_block_matched(object, G_SIGNAL_MATCH_DATA, 0, 0, NULL, | |
66 NULL, toolbar); | |
8317 | 67 gtk_imhtml_toggle_italic(GTK_IMHTML(toolbar->imhtml)); |
8481 | 68 g_signal_handlers_unblock_matched(object, G_SIGNAL_MATCH_DATA, 0, 0, NULL, |
69 NULL, toolbar); | |
70 g_object_unref(object); | |
10134 | 71 |
8317 | 72 gtk_widget_grab_focus(toolbar->imhtml); |
73 } | |
74 | |
75 static void | |
76 do_underline(GtkWidget *underline, GtkIMHtmlToolbar *toolbar) | |
77 { | |
8481 | 78 GObject *object; |
10134 | 79 |
8317 | 80 g_return_if_fail(toolbar); |
10134 | 81 |
8481 | 82 /* block the format_function_toggle handler */ |
83 object = g_object_ref(G_OBJECT(GTK_IMHTML(toolbar->imhtml))); | |
84 g_signal_handlers_block_matched(object, G_SIGNAL_MATCH_DATA, 0, 0, NULL, | |
85 NULL, toolbar); | |
8317 | 86 gtk_imhtml_toggle_underline(GTK_IMHTML(toolbar->imhtml)); |
8481 | 87 g_signal_handlers_unblock_matched(object, G_SIGNAL_MATCH_DATA, 0, 0, NULL, |
88 NULL, toolbar); | |
89 g_object_unref(object); | |
10134 | 90 |
8317 | 91 gtk_widget_grab_focus(toolbar->imhtml); |
92 } | |
93 | |
94 static void | |
95 do_small(GtkWidget *smalltb, GtkIMHtmlToolbar *toolbar) | |
96 { | |
97 g_return_if_fail(toolbar); | |
8380 | 98 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->smaller_size))) |
99 gtk_imhtml_font_shrink(GTK_IMHTML(toolbar->imhtml)); | |
8317 | 100 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->smaller_size), FALSE); |
101 gtk_widget_grab_focus(toolbar->imhtml); | |
102 } | |
103 | |
104 static void | |
105 do_big(GtkWidget *large, GtkIMHtmlToolbar *toolbar) | |
106 { | |
107 g_return_if_fail(toolbar); | |
8380 | 108 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->larger_size))) |
109 gtk_imhtml_font_grow(GTK_IMHTML(toolbar->imhtml)); | |
8317 | 110 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->larger_size), FALSE); |
111 gtk_widget_grab_focus(toolbar->imhtml); | |
112 } | |
113 | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
114 static void |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
115 destroy_toolbar_font(GtkWidget *widget, GdkEvent *event, |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
116 GtkIMHtmlToolbar *toolbar) |
8317 | 117 { |
118 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->font), FALSE); | |
119 | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
120 if (toolbar->font_dialog != NULL) |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
121 { |
8317 | 122 gtk_widget_destroy(toolbar->font_dialog); |
123 toolbar->font_dialog = NULL; | |
124 } | |
125 } | |
126 | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
127 static void |
10125 | 128 realize_toolbar_font(GtkWidget *widget, GtkIMHtmlToolbar *toolbar) |
129 { | |
130 GtkFontSelection *sel; | |
131 | |
132 sel = GTK_FONT_SELECTION(GTK_FONT_SELECTION_DIALOG(toolbar->font_dialog)->fontsel); | |
133 gtk_widget_hide_all(gtk_widget_get_parent(sel->size_entry)); | |
134 gtk_widget_show_all(sel->family_list); | |
135 gtk_widget_show(gtk_widget_get_parent(sel->family_list)); | |
136 gtk_widget_show(gtk_widget_get_parent(gtk_widget_get_parent(sel->family_list))); | |
137 } | |
138 | |
139 static void | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
140 cancel_toolbar_font(GtkWidget *widget, GtkIMHtmlToolbar *toolbar) |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
141 { |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
142 destroy_toolbar_font(widget, NULL, toolbar); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
143 } |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
144 |
8317 | 145 static void apply_font(GtkWidget *widget, GtkFontSelection *fontsel) |
146 { | |
147 /* this could be expanded to include font size, weight, etc. | |
148 but for now only works with font face */ | |
149 char *fontname; | |
150 char *space; | |
151 GtkIMHtmlToolbar *toolbar = g_object_get_data(G_OBJECT(fontsel), "gaim_toolbar"); | |
152 | |
153 fontname = gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(fontsel)); | |
154 | |
155 space = strrchr(fontname, ' '); | |
156 if(space && isdigit(*(space+1))) | |
157 *space = '\0'; | |
158 | |
159 gtk_imhtml_toggle_fontface(GTK_IMHTML(toolbar->imhtml), fontname); | |
160 | |
161 g_free(fontname); | |
162 | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
163 cancel_toolbar_font(NULL, toolbar); |
8317 | 164 } |
165 | |
166 static void | |
167 toggle_font(GtkWidget *font, GtkIMHtmlToolbar *toolbar) | |
168 { | |
9025 | 169 const char *fontname; |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
170 |
8317 | 171 g_return_if_fail(toolbar); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
172 |
9025 | 173 fontname = gtk_imhtml_get_current_fontface(GTK_IMHTML(toolbar->imhtml)); |
174 | |
8317 | 175 if (!toolbar->font_dialog) { |
176 toolbar->font_dialog = gtk_font_selection_dialog_new(_("Select Font")); | |
177 | |
178 g_object_set_data(G_OBJECT(toolbar->font_dialog), "gaim_toolbar", toolbar); | |
10134 | 179 |
9025 | 180 if(fontname) { |
181 char fonttif[128]; | |
182 g_snprintf(fonttif, sizeof(fonttif), "%s 12", fontname); | |
183 gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(toolbar->font_dialog), | |
184 fonttif); | |
185 } else { | |
186 gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(toolbar->font_dialog), | |
187 DEFAULT_FONT_FACE); | |
188 } | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
189 |
8317 | 190 g_signal_connect(G_OBJECT(toolbar->font_dialog), "delete_event", |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
191 G_CALLBACK(destroy_toolbar_font), toolbar); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
192 g_signal_connect(G_OBJECT(GTK_FONT_SELECTION_DIALOG(toolbar->font_dialog)->ok_button), "clicked", |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
193 G_CALLBACK(apply_font), toolbar->font_dialog); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
194 g_signal_connect(G_OBJECT(GTK_FONT_SELECTION_DIALOG(toolbar->font_dialog)->cancel_button), "clicked", |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
195 G_CALLBACK(cancel_toolbar_font), toolbar); |
10125 | 196 g_signal_connect_after(G_OBJECT(toolbar->font_dialog), "realize", |
197 G_CALLBACK(realize_toolbar_font), toolbar); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
198 |
8317 | 199 gtk_window_present(GTK_WINDOW(toolbar->font_dialog)); |
200 } else { | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
201 cancel_toolbar_font(NULL, toolbar); |
8317 | 202 } |
203 gtk_widget_grab_focus(toolbar->imhtml); | |
204 } | |
205 | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
206 static void |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
207 destroy_toolbar_fgcolor(GtkWidget *widget, GdkEvent *event, |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
208 GtkIMHtmlToolbar *toolbar) |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
209 { |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
210 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->fgcolor), FALSE); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
211 |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
212 if (toolbar->fgcolor_dialog != NULL) |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
213 { |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
214 gtk_widget_destroy(toolbar->fgcolor_dialog); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
215 toolbar->fgcolor_dialog = NULL; |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
216 } |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
217 } |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
218 |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
219 static void cancel_toolbar_fgcolor(GtkWidget *widget, |
8321
eb269b81fff8
[gaim-migrate @ 9045]
Christian Hammond <chipx86@chipx86.com>
parents:
8320
diff
changeset
|
220 GtkIMHtmlToolbar *toolbar) |
8317 | 221 { |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
222 destroy_toolbar_fgcolor(widget, NULL, toolbar); |
8317 | 223 } |
224 | |
225 static void do_fgcolor(GtkWidget *widget, GtkColorSelection *colorsel) | |
226 { | |
227 GdkColor text_color; | |
228 GtkIMHtmlToolbar *toolbar = g_object_get_data(G_OBJECT(colorsel), "gaim_toolbar"); | |
229 char *open_tag; | |
230 | |
231 open_tag = g_malloc(30); | |
232 gtk_color_selection_get_current_color(colorsel, &text_color); | |
233 g_snprintf(open_tag, 23, "#%02X%02X%02X", | |
234 text_color.red / 256, | |
235 text_color.green / 256, | |
236 text_color.blue / 256); | |
237 gtk_imhtml_toggle_forecolor(GTK_IMHTML(toolbar->imhtml), open_tag); | |
238 | |
239 g_free(open_tag); | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
240 cancel_toolbar_fgcolor(NULL, toolbar); |
8317 | 241 } |
242 | |
243 static void | |
244 toggle_fg_color(GtkWidget *color, GtkIMHtmlToolbar *toolbar) | |
245 { | |
246 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(color))) { | |
247 GtkWidget *colorsel; | |
9025 | 248 GdkColor fgcolor; |
249 const char *color = gtk_imhtml_get_current_forecolor(GTK_IMHTML(toolbar->imhtml)); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
250 |
8317 | 251 if (!toolbar->fgcolor_dialog) { |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
252 |
8317 | 253 toolbar->fgcolor_dialog = gtk_color_selection_dialog_new(_("Select Text Color")); |
254 colorsel = GTK_COLOR_SELECTION_DIALOG(toolbar->fgcolor_dialog)->colorsel; | |
9025 | 255 if (color) { |
256 gdk_color_parse(color, &fgcolor); | |
257 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel), &fgcolor); | |
258 } | |
259 | |
8317 | 260 g_object_set_data(G_OBJECT(colorsel), "gaim_toolbar", toolbar); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
261 |
8317 | 262 g_signal_connect(G_OBJECT(toolbar->fgcolor_dialog), "delete_event", |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
263 G_CALLBACK(destroy_toolbar_fgcolor), toolbar); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
264 g_signal_connect(G_OBJECT(GTK_COLOR_SELECTION_DIALOG(toolbar->fgcolor_dialog)->ok_button), "clicked", |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
265 G_CALLBACK(do_fgcolor), colorsel); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
266 g_signal_connect(G_OBJECT (GTK_COLOR_SELECTION_DIALOG(toolbar->fgcolor_dialog)->cancel_button), "clicked", |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
267 G_CALLBACK(cancel_toolbar_fgcolor), toolbar); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
268 |
8317 | 269 } |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
270 gtk_window_present(GTK_WINDOW(toolbar->fgcolor_dialog)); |
8317 | 271 } else if (toolbar->fgcolor_dialog != NULL) { |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
272 cancel_toolbar_fgcolor(color, toolbar); |
8317 | 273 } else { |
9863 | 274 /* gaim_gtk_advance_past(gtkconv, "<FONT COLOR>", "</FONT>"); */ |
8317 | 275 } |
276 gtk_widget_grab_focus(toolbar->imhtml); | |
277 } | |
278 | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
279 static void |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
280 destroy_toolbar_bgcolor(GtkWidget *widget, GdkEvent *event, |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
281 GtkIMHtmlToolbar *toolbar) |
8317 | 282 { |
283 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->bgcolor), FALSE); | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
284 |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
285 if (toolbar->bgcolor_dialog != NULL) |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
286 { |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
287 gtk_widget_destroy(toolbar->bgcolor_dialog); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
288 toolbar->bgcolor_dialog = NULL; |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
289 } |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
290 } |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
291 |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
292 static void |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
293 cancel_toolbar_bgcolor(GtkWidget *widget, GtkIMHtmlToolbar *toolbar) |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
294 { |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
295 destroy_toolbar_bgcolor(widget, NULL, toolbar); |
8317 | 296 } |
297 | |
298 static void do_bgcolor(GtkWidget *widget, GtkColorSelection *colorsel) | |
299 { | |
300 GdkColor text_color; | |
301 GtkIMHtmlToolbar *toolbar = g_object_get_data(G_OBJECT(colorsel), "gaim_toolbar"); | |
302 char *open_tag; | |
303 | |
304 open_tag = g_malloc(30); | |
305 gtk_color_selection_get_current_color(colorsel, &text_color); | |
306 g_snprintf(open_tag, 23, "#%02X%02X%02X", | |
307 text_color.red / 256, | |
308 text_color.green / 256, | |
309 text_color.blue / 256); | |
310 gtk_imhtml_toggle_backcolor(GTK_IMHTML(toolbar->imhtml), open_tag); | |
311 | |
312 g_free(open_tag); | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
313 cancel_toolbar_bgcolor(NULL, toolbar); |
8317 | 314 } |
315 | |
316 static void | |
317 toggle_bg_color(GtkWidget *color, GtkIMHtmlToolbar *toolbar) | |
318 { | |
319 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(color))) { | |
320 GtkWidget *colorsel; | |
9025 | 321 GdkColor bgcolor; |
322 const char *color = gtk_imhtml_get_current_backcolor(GTK_IMHTML(toolbar->imhtml)); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
323 |
8317 | 324 if (!toolbar->bgcolor_dialog) { |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
325 |
8359 | 326 toolbar->bgcolor_dialog = gtk_color_selection_dialog_new(_("Select Background Color")); |
8317 | 327 colorsel = GTK_COLOR_SELECTION_DIALOG(toolbar->bgcolor_dialog)->colorsel; |
9025 | 328 if (color) { |
329 gdk_color_parse(color, &bgcolor); | |
330 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel), &bgcolor); | |
331 } | |
332 | |
8317 | 333 g_object_set_data(G_OBJECT(colorsel), "gaim_toolbar", toolbar); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
334 |
8317 | 335 g_signal_connect(G_OBJECT(toolbar->bgcolor_dialog), "delete_event", |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
336 G_CALLBACK(destroy_toolbar_bgcolor), toolbar); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
337 g_signal_connect(G_OBJECT(GTK_COLOR_SELECTION_DIALOG(toolbar->bgcolor_dialog)->ok_button), "clicked", |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
338 G_CALLBACK(do_bgcolor), colorsel); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
339 g_signal_connect(G_OBJECT(GTK_COLOR_SELECTION_DIALOG(toolbar->bgcolor_dialog)->cancel_button), "clicked", |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
340 G_CALLBACK(cancel_toolbar_bgcolor), toolbar); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
341 |
8317 | 342 } |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
343 gtk_window_present(GTK_WINDOW(toolbar->bgcolor_dialog)); |
8317 | 344 } else if (toolbar->bgcolor_dialog != NULL) { |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
345 cancel_toolbar_bgcolor(color, toolbar); |
8317 | 346 } else { |
9863 | 347 /* gaim_gtk_advance_past(gtkconv, "<FONT COLOR>", "</FONT>"); */ |
8317 | 348 } |
349 gtk_widget_grab_focus(toolbar->imhtml); | |
350 } | |
351 | |
352 static void | |
353 cancel_link_cb(GtkIMHtmlToolbar *toolbar, GaimRequestFields *fields) | |
354 { | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
355 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->link), FALSE); |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
356 |
8317 | 357 toolbar->link_dialog = NULL; |
358 } | |
359 | |
360 static void | |
361 close_link_dialog(GtkIMHtmlToolbar *toolbar) | |
362 { | |
363 if (toolbar->link_dialog != NULL) | |
364 { | |
365 gaim_request_close(GAIM_REQUEST_FIELDS, toolbar->link_dialog); | |
366 toolbar->link_dialog = NULL; | |
367 } | |
368 } | |
369 | |
370 static void | |
371 do_insert_link_cb(GtkIMHtmlToolbar *toolbar, GaimRequestFields *fields) | |
372 { | |
373 const char *url, *description; | |
374 | |
375 url = gaim_request_fields_get_string(fields, "url"); | |
9041 | 376 if (GTK_IMHTML(toolbar->imhtml)->format_functions & GTK_IMHTML_LINKDESC) |
377 description = gaim_request_fields_get_string(fields, "description"); | |
378 else | |
379 description = NULL; | |
8317 | 380 |
381 if (description == NULL) | |
382 description = url; | |
383 | |
8677 | 384 gtk_imhtml_insert_link(GTK_IMHTML(toolbar->imhtml), |
385 gtk_text_buffer_get_insert(GTK_IMHTML(toolbar->imhtml)->text_buffer), | |
386 url, description); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
387 |
8317 | 388 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->link), FALSE); |
389 | |
390 toolbar->link_dialog = NULL; | |
391 } | |
392 | |
393 static void | |
394 insert_link_cb(GtkWidget *w, GtkIMHtmlToolbar *toolbar) | |
395 { | |
396 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->link))) { | |
397 GaimRequestFields *fields; | |
398 GaimRequestFieldGroup *group; | |
399 GaimRequestField *field; | |
9599 | 400 GtkTextIter start, end; |
9041 | 401 char *msg; |
9599 | 402 char *desc = NULL; |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
403 |
8317 | 404 fields = gaim_request_fields_new(); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
405 |
8317 | 406 group = gaim_request_field_group_new(NULL); |
407 gaim_request_fields_add_group(fields, group); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
408 |
8317 | 409 field = gaim_request_field_string_new("url", _("_URL"), NULL, FALSE); |
410 gaim_request_field_set_required(field, TRUE); | |
411 gaim_request_field_group_add_field(group, field); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
412 |
9041 | 413 if(GTK_IMHTML(toolbar->imhtml)->format_functions & GTK_IMHTML_LINKDESC) { |
9599 | 414 if (gtk_text_buffer_get_selection_bounds(GTK_IMHTML(toolbar->imhtml)->text_buffer, &start, &end)) { |
415 desc = gtk_imhtml_get_text(GTK_IMHTML(toolbar->imhtml), &start, &end); | |
416 } | |
9041 | 417 field = gaim_request_field_string_new("description", _("_Description"), |
9599 | 418 desc, FALSE); |
9041 | 419 gaim_request_field_group_add_field(group, field); |
420 msg = g_strdup(_("Please enter the URL and description of the " | |
421 "link that you want to insert. The description " | |
422 "is optional.")); | |
423 } else { | |
424 msg = g_strdup(_("Please enter the URL of the " | |
425 "link that you want to insert.")); | |
426 } | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
427 |
8317 | 428 toolbar->link_dialog = |
429 gaim_request_fields(toolbar, _("Insert Link"), | |
430 NULL, | |
9041 | 431 msg, |
8317 | 432 fields, |
433 _("_Insert"), G_CALLBACK(do_insert_link_cb), | |
434 _("Cancel"), G_CALLBACK(cancel_link_cb), | |
435 toolbar); | |
9041 | 436 g_free(msg); |
9599 | 437 g_free(desc); |
8322
ffb601c6b833
[gaim-migrate @ 9046]
Christian Hammond <chipx86@chipx86.com>
parents:
8321
diff
changeset
|
438 } else { |
8317 | 439 close_link_dialog(toolbar); |
440 } | |
441 gtk_widget_grab_focus(toolbar->imhtml); | |
442 } | |
443 | |
444 | |
445 static void | |
9522 | 446 do_insert_image_cb(GtkWidget *widget, int response, GtkIMHtmlToolbar *toolbar) |
8317 | 447 { |
9522 | 448 gchar *filename, *name, *buf; |
449 char *filedata; | |
8317 | 450 size_t size; |
451 GError *error = NULL; | |
452 int id; | |
8962 | 453 GtkTextIter iter; |
454 GtkTextMark *ins; | |
8317 | 455 |
9522 | 456 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
457 if (response != GTK_RESPONSE_ACCEPT) { | |
458 #else /* FILECHOOSER */ | |
459 if (response != GTK_RESPONSE_OK) { | |
460 #endif /* FILECHOOSER */ | |
8317 | 461 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->image), FALSE); |
462 return; | |
463 } | |
464 | |
9522 | 465 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
466 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget)); | |
467 #else /* FILECHOOSER */ | |
468 filename = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(widget))); | |
469 #endif /* FILECHOOSER */ | |
8317 | 470 |
9522 | 471 if (filename == NULL) { |
8317 | 472 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->image), FALSE); |
473 return; | |
474 } | |
475 | |
9522 | 476 #if !GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
477 if (gaim_gtk_check_if_dir(filename, GTK_FILE_SELECTION(widget))) { | |
478 g_free(filename); | |
479 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->image), FALSE); | |
480 return; | |
481 } | |
482 #endif /* FILECHOOSER */ | |
483 | |
484 /* The following triggers a callback that closes the widget */ | |
8317 | 485 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->image), FALSE); |
486 | |
9522 | 487 if (!g_file_get_contents(filename, &filedata, &size, &error)) { |
8317 | 488 gaim_notify_error(NULL, NULL, error->message, NULL); |
489 | |
490 g_error_free(error); | |
9522 | 491 g_free(filename); |
8317 | 492 |
493 return; | |
494 } | |
495 | |
9522 | 496 name = strrchr(filename, G_DIR_SEPARATOR) + 1; |
8317 | 497 |
9522 | 498 id = gaim_imgstore_add(filedata, size, name); |
8317 | 499 g_free(filedata); |
500 | |
9522 | 501 if (id == 0) { |
502 buf = g_strdup_printf(_("Failed to store image: %s\n"), filename); | |
8317 | 503 gaim_notify_error(NULL, NULL, buf, NULL); |
504 | |
505 g_free(buf); | |
9522 | 506 g_free(filename); |
8317 | 507 |
508 return; | |
509 } | |
510 | |
9522 | 511 g_free(filename); |
512 | |
8962 | 513 ins = gtk_text_buffer_get_insert(gtk_text_view_get_buffer(GTK_TEXT_VIEW(toolbar->imhtml))); |
514 gtk_text_buffer_get_iter_at_mark(gtk_text_view_get_buffer(GTK_TEXT_VIEW(toolbar->imhtml)), | |
9522 | 515 &iter, ins); |
8962 | 516 gtk_imhtml_insert_image_at_iter(GTK_IMHTML(toolbar->imhtml), id, &iter); |
517 gaim_imgstore_unref(id); | |
8317 | 518 } |
519 | |
520 | |
521 static void | |
522 insert_image_cb(GtkWidget *save, GtkIMHtmlToolbar *toolbar) | |
523 { | |
524 GtkWidget *window; | |
525 | |
526 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->image))) { | |
9522 | 527 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
528 window = gtk_file_chooser_dialog_new(_("Insert Image"), | |
529 NULL, | |
530 GTK_FILE_CHOOSER_ACTION_OPEN, | |
531 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | |
532 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, | |
533 NULL); | |
534 gtk_dialog_set_default_response(GTK_DIALOG(window), GTK_RESPONSE_ACCEPT); | |
535 g_signal_connect(G_OBJECT(GTK_FILE_CHOOSER(window)), | |
536 "response", G_CALLBACK(do_insert_image_cb), toolbar); | |
537 #else /* FILECHOOSER */ | |
8317 | 538 window = gtk_file_selection_new(_("Insert Image")); |
539 gtk_dialog_set_default_response(GTK_DIALOG(window), GTK_RESPONSE_OK); | |
540 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(window)), | |
541 "response", G_CALLBACK(do_insert_image_cb), toolbar); | |
9522 | 542 #endif /* FILECHOOSER */ |
8317 | 543 |
544 gtk_widget_show(window); | |
545 toolbar->image_dialog = window; | |
546 } else { | |
547 gtk_widget_destroy(toolbar->image_dialog); | |
548 toolbar->image_dialog = NULL; | |
549 } | |
9522 | 550 |
8317 | 551 gtk_widget_grab_focus(toolbar->imhtml); |
552 } | |
553 | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
554 static void |
10134 | 555 destroy_smiley_menu(GtkWidget *widget, GtkIMHtmlToolbar *toolbar) |
8317 | 556 { |
10134 | 557 if (toolbar->smiley_menu != NULL) |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
558 { |
10134 | 559 gtk_widget_destroy(toolbar->smiley_menu); |
560 toolbar->smiley_menu = NULL; | |
8317 | 561 } |
562 } | |
563 | |
10134 | 564 static void |
565 deactivate_smiley_menu(GtkWidget *widget, GtkIMHtmlToolbar *toolbar) | |
566 { | |
567 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->smiley), FALSE); | |
568 gtk_button_released(GTK_BUTTON(toolbar->smiley)); | |
569 } | |
8317 | 570 |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
571 static void |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
572 insert_smiley_text(GtkWidget *widget, GtkIMHtmlToolbar *toolbar) |
8317 | 573 { |
9027 | 574 char *smiley_text, *escaped_smiley; |
575 | |
576 smiley_text = g_object_get_data(G_OBJECT(widget), "smiley_text"); | |
577 escaped_smiley = gaim_escape_html(smiley_text); | |
8317 | 578 |
8456 | 579 gtk_imhtml_insert_smiley(GTK_IMHTML(toolbar->imhtml), |
580 GTK_IMHTML(toolbar->imhtml)->protocol_name, | |
9027 | 581 escaped_smiley); |
8317 | 582 |
9027 | 583 g_free(escaped_smiley); |
10134 | 584 destroy_smiley_menu(NULL, toolbar); |
8317 | 585 } |
586 | |
10134 | 587 static void add_smiley(GtkIMHtmlToolbar *toolbar, GtkWidget *menu, int row, int col, char *filename, char *face) |
8317 | 588 { |
589 GtkWidget *image; | |
10134 | 590 GtkWidget *menuitem; |
8317 | 591 |
592 image = gtk_image_new_from_file(filename); | |
10134 | 593 menuitem = gtk_image_menu_item_new_with_label(""); |
594 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); | |
595 g_object_set_data(G_OBJECT(menuitem), "smiley_text", face); | |
596 gtk_tooltips_set_tip(toolbar->tooltips, menuitem, face, NULL); | |
597 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(insert_smiley_text), toolbar); | |
598 gtk_menu_attach(GTK_MENU(menu), menuitem, col, col+1, row, row+1); | |
8317 | 599 } |
600 | |
601 static gboolean smiley_is_unique(GSList *list, GtkIMHtmlSmiley *smiley) { | |
602 while(list) { | |
603 GtkIMHtmlSmiley *cur = list->data; | |
604 if(!strcmp(cur->file, smiley->file)) | |
605 return FALSE; | |
606 list = list->next; | |
607 } | |
608 return TRUE; | |
609 } | |
610 | |
611 | |
612 static void | |
613 insert_smiley_cb(GtkWidget *smiley, GtkIMHtmlToolbar *toolbar) | |
614 { | |
10134 | 615 GtkWidget *menu; |
616 GSList *smileys, *unique_smileys = NULL; | |
617 int width; | |
618 int row = 0, col = 0; | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
619 |
10134 | 620 destroy_smiley_menu(NULL, toolbar); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
621 |
10134 | 622 if (toolbar->sml) |
623 smileys = get_proto_smileys(toolbar->sml); | |
624 else | |
625 smileys = get_proto_smileys(NULL); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
626 |
10134 | 627 while(smileys) { |
628 GtkIMHtmlSmiley *smiley = smileys->data; | |
629 if(!smiley->hidden) { | |
630 if(smiley_is_unique(unique_smileys, smiley)) | |
631 unique_smileys = g_slist_append(unique_smileys, smiley); | |
8317 | 632 } |
10134 | 633 smileys = smileys->next; |
634 } | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
635 |
10134 | 636 menu = gtk_menu_new(); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
637 |
10134 | 638 if(g_slist_length(unique_smileys)) { |
8892 | 639 |
10134 | 640 width = floor(sqrt(g_slist_length(unique_smileys))); |
8892 | 641 |
10134 | 642 /* build menu */ |
643 while(unique_smileys) { | |
644 GtkIMHtmlSmiley *smiley = unique_smileys->data; | |
645 if(!smiley->hidden) { | |
646 add_smiley(toolbar, menu, row, col, smiley->file, smiley->smile); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
647 |
10134 | 648 if(++col >= width) { |
649 col = 0; | |
650 row++; | |
651 } | |
652 } | |
653 unique_smileys = unique_smileys->next; | |
654 } | |
655 } | |
656 else { | |
657 GtkWidget *menuitem; | |
658 menuitem = gtk_menu_item_new_with_label(_("This theme has no available smileys.")); | |
659 gtk_widget_set_sensitive(menuitem, FALSE); | |
660 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
661 } | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
662 |
10134 | 663 /* connect signals */ |
664 g_signal_connect(G_OBJECT(menu), "deactivate", | |
665 G_CALLBACK(deactivate_smiley_menu), toolbar); | |
666 g_signal_connect(G_OBJECT(menu), "selection-done", | |
667 G_CALLBACK(destroy_smiley_menu), toolbar); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
668 |
10134 | 669 /* show everything */ |
670 gtk_widget_show_all(menu); | |
671 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time()); | |
672 toolbar->smiley_menu = menu; | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
673 |
8317 | 674 gtk_widget_grab_focus(toolbar->imhtml); |
675 } | |
676 | |
8420 | 677 static void update_buttons_cb(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons, GtkIMHtmlToolbar *toolbar) |
678 { | |
679 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->bold), buttons & GTK_IMHTML_BOLD); | |
680 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->italic), buttons & GTK_IMHTML_ITALIC); | |
681 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->underline), buttons & GTK_IMHTML_UNDERLINE); | |
682 | |
683 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->larger_size), buttons & GTK_IMHTML_GROW); | |
684 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->smaller_size), buttons & GTK_IMHTML_SHRINK); | |
685 | |
686 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->font), buttons & GTK_IMHTML_FACE); | |
687 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->fgcolor), buttons & GTK_IMHTML_FORECOLOR); | |
688 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->bgcolor), buttons & GTK_IMHTML_BACKCOLOR); | |
689 | |
690 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->image), buttons & GTK_IMHTML_IMAGE); | |
691 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->link), buttons & GTK_IMHTML_LINK); | |
692 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->smiley), buttons & GTK_IMHTML_SMILEY); | |
8481 | 693 } |
8420 | 694 |
8481 | 695 /* we call this when we want to _set_active the toggle button, it'll |
696 * block the callback thats connected to the button so we don't have to | |
697 * do the double toggling hack | |
698 */ | |
699 static void toggle_button_set_active_block(GtkToggleButton *button, | |
700 gboolean is_active, | |
701 GtkIMHtmlToolbar *toolbar) | |
702 { | |
703 GObject *object; | |
704 g_return_if_fail(toolbar); | |
705 | |
706 object = g_object_ref(button); | |
707 g_signal_handlers_block_matched(object, G_SIGNAL_MATCH_DATA, | |
708 0, 0, NULL, NULL, toolbar); | |
709 gtk_toggle_button_set_active(button, is_active); | |
710 g_signal_handlers_unblock_matched(object, G_SIGNAL_MATCH_DATA, | |
711 0, 0, NULL, NULL, toolbar); | |
712 g_object_unref(object); | |
8420 | 713 } |
714 | |
715 static void toggle_button_cb(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons, GtkIMHtmlToolbar *toolbar) | |
716 { | |
8481 | 717 if (buttons & GTK_IMHTML_BOLD) |
718 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->bold), | |
719 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->bold)), | |
720 toolbar); | |
8420 | 721 |
8481 | 722 if (buttons & GTK_IMHTML_ITALIC) |
723 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->italic), | |
724 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->italic)), | |
725 toolbar); | |
8420 | 726 |
8481 | 727 if (buttons & GTK_IMHTML_UNDERLINE) |
728 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->underline), | |
729 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->underline)), | |
730 toolbar); | |
8420 | 731 } |
732 | |
8427 | 733 static void reset_buttons_cb(GtkIMHtml *imhtml, GtkIMHtmlToolbar *toolbar) |
734 { | |
8481 | 735 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->bold))) |
736 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->bold), FALSE, | |
737 toolbar); | |
10134 | 738 |
8481 | 739 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->italic))) |
740 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->italic), | |
741 FALSE, toolbar); | |
10134 | 742 |
8481 | 743 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->underline))) |
744 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->underline), | |
745 FALSE, toolbar); | |
746 } | |
8516 | 747 |
748 static void update_buttons(GtkIMHtmlToolbar *toolbar) { | |
8506 | 749 gboolean bold, italic, underline; |
10134 | 750 |
8506 | 751 bold = italic = underline = FALSE; |
8516 | 752 gtk_imhtml_get_current_format(GTK_IMHTML(toolbar->imhtml), |
753 &bold, &italic, &underline); | |
8506 | 754 |
755 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->bold)) != bold) | |
756 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->bold), bold, | |
757 toolbar); | |
8516 | 758 |
8506 | 759 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->italic)) != italic) |
760 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->italic), italic, | |
761 toolbar); | |
8516 | 762 |
8506 | 763 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->underline)) != underline) |
764 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->underline), | |
8677 | 765 underline, toolbar); |
8506 | 766 } |
8481 | 767 |
8516 | 768 static void update_format_cb(GtkIMHtml *imhtml, GtkIMHtmlToolbar *toolbar) { |
769 update_buttons(toolbar); | |
770 } | |
8481 | 771 |
8516 | 772 static void mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *location, |
773 GtkTextMark *mark, GtkIMHtmlToolbar *toolbar) | |
774 { | |
775 if(mark != gtk_text_buffer_get_insert(buffer)) | |
776 return; | |
777 | |
778 update_buttons(toolbar); | |
8427 | 779 } |
780 | |
8317 | 781 enum { |
782 LAST_SIGNAL | |
783 }; | |
9863 | 784 /* static guint signals [LAST_SIGNAL] = { 0 }; */ |
8317 | 785 |
786 static void | |
787 gtk_imhtmltoolbar_finalize (GObject *object) | |
788 { | |
8391 | 789 GtkIMHtmlToolbar *toolbar = GTK_IMHTMLTOOLBAR(object); |
8317 | 790 |
8685
2ac2f4cf1de5
[gaim-migrate @ 9438]
Christian Hammond <chipx86@chipx86.com>
parents:
8677
diff
changeset
|
791 if (toolbar->image_dialog != NULL) |
2ac2f4cf1de5
[gaim-migrate @ 9438]
Christian Hammond <chipx86@chipx86.com>
parents:
8677
diff
changeset
|
792 { |
2ac2f4cf1de5
[gaim-migrate @ 9438]
Christian Hammond <chipx86@chipx86.com>
parents:
8677
diff
changeset
|
793 gtk_widget_destroy(toolbar->image_dialog); |
2ac2f4cf1de5
[gaim-migrate @ 9438]
Christian Hammond <chipx86@chipx86.com>
parents:
8677
diff
changeset
|
794 toolbar->image_dialog = NULL; |
2ac2f4cf1de5
[gaim-migrate @ 9438]
Christian Hammond <chipx86@chipx86.com>
parents:
8677
diff
changeset
|
795 } |
2ac2f4cf1de5
[gaim-migrate @ 9438]
Christian Hammond <chipx86@chipx86.com>
parents:
8677
diff
changeset
|
796 |
10134 | 797 destroy_toolbar_font(NULL, NULL, toolbar); |
798 destroy_smiley_menu(NULL, toolbar); | |
799 destroy_toolbar_bgcolor(NULL, NULL, toolbar); | |
800 destroy_toolbar_fgcolor(NULL, NULL, toolbar); | |
801 close_link_dialog(toolbar); | |
8784
48dd097eb475
[gaim-migrate @ 9546]
Christian Hammond <chipx86@chipx86.com>
parents:
8756
diff
changeset
|
802 |
8427 | 803 if (toolbar->sml) |
804 free(toolbar->sml); | |
8391 | 805 gtk_object_sink(GTK_OBJECT(toolbar->tooltips)); |
8317 | 806 |
8391 | 807 G_OBJECT_CLASS(parent_class)->finalize (object); |
8317 | 808 } |
809 | |
810 /* Boring GTK stuff */ | |
811 static void gtk_imhtmltoolbar_class_init (GtkIMHtmlToolbarClass *class) | |
812 { | |
813 GtkObjectClass *object_class; | |
814 GObjectClass *gobject_class; | |
815 object_class = (GtkObjectClass*) class; | |
816 gobject_class = (GObjectClass*) class; | |
10080 | 817 parent_class = gtk_type_class(GTK_TYPE_HBOX); |
8317 | 818 gobject_class->finalize = gtk_imhtmltoolbar_finalize; |
819 } | |
820 | |
821 static void gtk_imhtmltoolbar_init (GtkIMHtmlToolbar *toolbar) | |
822 { | |
10085 | 823 GtkWidget *hbox = GTK_WIDGET(toolbar); |
8317 | 824 GtkWidget *button; |
825 GtkWidget *sep; | |
826 GtkSizeGroup *sg; | |
827 | |
828 toolbar->imhtml = NULL; | |
829 toolbar->font_dialog = NULL; | |
830 toolbar->fgcolor_dialog = NULL; | |
831 toolbar->bgcolor_dialog = NULL; | |
832 toolbar->link_dialog = NULL; | |
10134 | 833 toolbar->smiley_menu = NULL; |
8317 | 834 toolbar->image_dialog = NULL; |
835 | |
836 toolbar->tooltips = gtk_tooltips_new(); | |
10134 | 837 |
10080 | 838 gtk_box_set_spacing(GTK_BOX(toolbar), 6); |
8317 | 839 sg = gtk_size_group_new(GTK_SIZE_GROUP_BOTH); |
840 | |
841 /* Bold */ | |
842 button = gaim_pixbuf_toolbar_button_from_stock(GTK_STOCK_BOLD); | |
843 gtk_size_group_add_widget(sg, button); | |
844 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
845 gtk_tooltips_set_tip(toolbar->tooltips, button, _("Bold"), NULL); | |
846 | |
847 g_signal_connect(G_OBJECT(button), "clicked", | |
848 G_CALLBACK(do_bold), toolbar); | |
849 | |
850 toolbar->bold = button; | |
851 | |
852 /* Italic */ | |
853 button = gaim_pixbuf_toolbar_button_from_stock(GTK_STOCK_ITALIC); | |
854 gtk_size_group_add_widget(sg, button); | |
855 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
856 gtk_tooltips_set_tip(toolbar->tooltips, button, _("Italic"), NULL); | |
857 | |
858 g_signal_connect(G_OBJECT(button), "clicked", | |
859 G_CALLBACK(do_italic), toolbar); | |
860 | |
861 toolbar->italic = button; | |
862 | |
863 /* Underline */ | |
864 button = gaim_pixbuf_toolbar_button_from_stock(GTK_STOCK_UNDERLINE); | |
865 gtk_size_group_add_widget(sg, button); | |
866 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
867 gtk_tooltips_set_tip(toolbar->tooltips, button, _("Underline"), NULL); | |
868 | |
869 g_signal_connect(G_OBJECT(button), "clicked", | |
870 G_CALLBACK(do_underline), toolbar); | |
871 | |
872 toolbar->underline = button; | |
873 | |
874 /* Sep */ | |
875 sep = gtk_vseparator_new(); | |
876 gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0); | |
877 | |
878 /* Increase font size */ | |
879 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_TEXT_BIGGER); | |
880 gtk_size_group_add_widget(sg, button); | |
881 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
882 gtk_tooltips_set_tip(toolbar->tooltips, button, | |
883 _("Larger font size"), NULL); | |
884 | |
885 g_signal_connect(G_OBJECT(button), "clicked", | |
886 G_CALLBACK(do_big), toolbar); | |
887 | |
888 toolbar->larger_size = button; | |
889 | |
890 /* Decrease font size */ | |
891 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_TEXT_SMALLER); | |
892 gtk_size_group_add_widget(sg, button); | |
893 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
894 gtk_tooltips_set_tip(toolbar->tooltips, button, | |
895 _("Smaller font size"), NULL); | |
896 | |
897 g_signal_connect(G_OBJECT(button), "clicked", | |
898 G_CALLBACK(do_small), toolbar); | |
899 | |
900 toolbar->smaller_size = button; | |
901 | |
902 /* Sep */ | |
903 sep = gtk_vseparator_new(); | |
904 gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0); | |
905 | |
906 /* Font Face */ | |
907 | |
908 button = gaim_pixbuf_toolbar_button_from_stock(GTK_STOCK_SELECT_FONT); | |
909 gtk_size_group_add_widget(sg, button); | |
910 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
911 gtk_tooltips_set_tip(toolbar->tooltips, button, | |
912 _("Font Face"), NULL); | |
913 | |
914 g_signal_connect(G_OBJECT(button), "clicked", | |
915 G_CALLBACK(toggle_font), toolbar); | |
916 | |
917 toolbar->font = button; | |
918 | |
919 /* Foreground Color */ | |
920 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_FGCOLOR); | |
921 gtk_size_group_add_widget(sg, button); | |
922 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
923 gtk_tooltips_set_tip(toolbar->tooltips, button, | |
924 _("Foreground font color"), NULL); | |
925 | |
926 g_signal_connect(G_OBJECT(button), "clicked", | |
927 G_CALLBACK(toggle_fg_color), toolbar); | |
928 | |
929 toolbar->fgcolor = button; | |
930 | |
931 /* Background Color */ | |
932 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_BGCOLOR); | |
933 gtk_size_group_add_widget(sg, button); | |
934 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
935 gtk_tooltips_set_tip(toolbar->tooltips, button, | |
936 _("Background color"), NULL); | |
937 | |
938 g_signal_connect(G_OBJECT(button), "clicked", | |
939 G_CALLBACK(toggle_bg_color), toolbar); | |
940 | |
941 toolbar->bgcolor = button; | |
942 | |
943 /* Sep */ | |
944 sep = gtk_vseparator_new(); | |
945 gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0); | |
946 | |
947 /* Insert Link */ | |
948 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_LINK); | |
949 gtk_size_group_add_widget(sg, button); | |
950 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
951 gtk_tooltips_set_tip(toolbar->tooltips, button, _("Insert link"), NULL); | |
952 g_signal_connect(G_OBJECT(button), "clicked", | |
953 G_CALLBACK(insert_link_cb), toolbar); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
954 |
8317 | 955 toolbar->link = button; |
956 | |
957 /* Insert IM Image */ | |
958 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_IMAGE); | |
959 gtk_size_group_add_widget(sg, button); | |
960 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
961 gtk_tooltips_set_tip(toolbar->tooltips, button, _("Insert image"), NULL); | |
962 | |
963 g_signal_connect(G_OBJECT(button), "clicked", | |
964 G_CALLBACK(insert_image_cb), toolbar); | |
965 | |
966 toolbar->image = button; | |
967 | |
968 /* Insert Smiley */ | |
969 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_SMILEY); | |
970 gtk_size_group_add_widget(sg, button); | |
971 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
972 gtk_tooltips_set_tip(toolbar->tooltips, button, _("Insert smiley"), NULL); | |
973 | |
10134 | 974 g_signal_connect(G_OBJECT(button), "pressed", |
8317 | 975 G_CALLBACK(insert_smiley_cb), toolbar); |
976 | |
977 toolbar->smiley = button; | |
978 | |
8427 | 979 toolbar->sml = NULL; |
8317 | 980 gtk_widget_show_all(hbox); |
981 } | |
982 | |
983 GtkWidget *gtk_imhtmltoolbar_new() | |
984 { | |
985 return GTK_WIDGET(g_object_new(gtk_imhtmltoolbar_get_type(), NULL)); | |
986 } | |
987 | |
988 GType gtk_imhtmltoolbar_get_type() | |
989 { | |
990 static GType imhtmltoolbar_type = 0; | |
991 | |
992 if (!imhtmltoolbar_type) { | |
993 static const GTypeInfo imhtmltoolbar_info = { | |
994 sizeof(GtkIMHtmlToolbarClass), | |
995 NULL, | |
996 NULL, | |
997 (GClassInitFunc) gtk_imhtmltoolbar_class_init, | |
998 NULL, | |
999 NULL, | |
1000 sizeof (GtkIMHtmlToolbar), | |
1001 0, | |
1002 (GInstanceInitFunc) gtk_imhtmltoolbar_init | |
1003 }; | |
1004 | |
10080 | 1005 imhtmltoolbar_type = g_type_register_static(GTK_TYPE_HBOX, |
8317 | 1006 "GtkIMHtmlToolbar", &imhtmltoolbar_info, 0); |
1007 } | |
1008 | |
1009 return imhtmltoolbar_type; | |
1010 } | |
1011 | |
1012 | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
1013 void gtk_imhtmltoolbar_attach(GtkIMHtmlToolbar *toolbar, GtkWidget *imhtml) |
8317 | 1014 { |
8788 | 1015 GtkIMHtmlButtons buttons; |
8481 | 1016 gboolean bold, italic, underline; |
1017 | |
8325
415283e39bce
[gaim-migrate @ 9049]
Christian Hammond <chipx86@chipx86.com>
parents:
8324
diff
changeset
|
1018 g_return_if_fail(toolbar != NULL); |
415283e39bce
[gaim-migrate @ 9049]
Christian Hammond <chipx86@chipx86.com>
parents:
8324
diff
changeset
|
1019 g_return_if_fail(GTK_IS_IMHTMLTOOLBAR(toolbar)); |
415283e39bce
[gaim-migrate @ 9049]
Christian Hammond <chipx86@chipx86.com>
parents:
8324
diff
changeset
|
1020 g_return_if_fail(imhtml != NULL); |
415283e39bce
[gaim-migrate @ 9049]
Christian Hammond <chipx86@chipx86.com>
parents:
8324
diff
changeset
|
1021 g_return_if_fail(GTK_IS_IMHTML(imhtml)); |
415283e39bce
[gaim-migrate @ 9049]
Christian Hammond <chipx86@chipx86.com>
parents:
8324
diff
changeset
|
1022 |
8317 | 1023 toolbar->imhtml = imhtml; |
8506 | 1024 g_signal_connect(G_OBJECT(imhtml), "format_buttons_update", G_CALLBACK(update_buttons_cb), toolbar); |
8420 | 1025 g_signal_connect(G_OBJECT(imhtml), "format_function_toggle", G_CALLBACK(toggle_button_cb), toolbar); |
8427 | 1026 g_signal_connect(G_OBJECT(imhtml), "format_function_clear", G_CALLBACK(reset_buttons_cb), toolbar); |
8506 | 1027 g_signal_connect(G_OBJECT(imhtml), "format_function_update", G_CALLBACK(update_format_cb), toolbar); |
8516 | 1028 g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set", G_CALLBACK(mark_set_cb), toolbar); |
8481 | 1029 |
8788 | 1030 buttons = gtk_imhtml_get_format_functions(GTK_IMHTML(imhtml)); |
8807 | 1031 update_buttons_cb(GTK_IMHTML(imhtml), buttons, toolbar); |
8788 | 1032 |
8481 | 1033 bold = italic = underline = FALSE; |
1034 | |
8516 | 1035 gtk_imhtml_get_current_format(GTK_IMHTML(imhtml), &bold, &italic, &underline); |
10134 | 1036 |
8481 | 1037 if(bold) |
1038 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->bold), bold, | |
1039 toolbar); | |
10134 | 1040 |
8481 | 1041 if(italic) |
1042 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->italic), italic, | |
1043 toolbar); | |
1044 | |
1045 if(underline) | |
1046 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->underline), | |
1047 underline, toolbar); | |
8317 | 1048 } |
8427 | 1049 |
1050 void gtk_imhtmltoolbar_associate_smileys(GtkIMHtmlToolbar *toolbar, const char *proto_id) | |
1051 { | |
1052 if (toolbar->sml) | |
1053 g_free(toolbar->sml); | |
10134 | 1054 |
8427 | 1055 toolbar->sml = g_strdup(proto_id); |
1056 } |