Mercurial > pidgin
annotate src/gtkimhtmltoolbar.c @ 10230:e76416d46af8
[gaim-migrate @ 11365]
Not halloween anymore.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 22 Nov 2004 04:52:22 +0000 |
parents | 5fb5c447eb4f |
children | ec140184437b |
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 { |
10135 | 118 if (widget != NULL) |
119 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->font), FALSE); | |
8317 | 120 |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
121 if (toolbar->font_dialog != NULL) |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
122 { |
8317 | 123 gtk_widget_destroy(toolbar->font_dialog); |
124 toolbar->font_dialog = NULL; | |
125 } | |
126 } | |
127 | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
128 static void |
10125 | 129 realize_toolbar_font(GtkWidget *widget, GtkIMHtmlToolbar *toolbar) |
130 { | |
131 GtkFontSelection *sel; | |
132 | |
133 sel = GTK_FONT_SELECTION(GTK_FONT_SELECTION_DIALOG(toolbar->font_dialog)->fontsel); | |
134 gtk_widget_hide_all(gtk_widget_get_parent(sel->size_entry)); | |
135 gtk_widget_show_all(sel->family_list); | |
136 gtk_widget_show(gtk_widget_get_parent(sel->family_list)); | |
137 gtk_widget_show(gtk_widget_get_parent(gtk_widget_get_parent(sel->family_list))); | |
138 } | |
139 | |
140 static void | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
141 cancel_toolbar_font(GtkWidget *widget, GtkIMHtmlToolbar *toolbar) |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
142 { |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
143 destroy_toolbar_font(widget, NULL, toolbar); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
144 } |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
145 |
8317 | 146 static void apply_font(GtkWidget *widget, GtkFontSelection *fontsel) |
147 { | |
148 /* this could be expanded to include font size, weight, etc. | |
149 but for now only works with font face */ | |
150 char *fontname; | |
151 char *space; | |
152 GtkIMHtmlToolbar *toolbar = g_object_get_data(G_OBJECT(fontsel), "gaim_toolbar"); | |
153 | |
154 fontname = gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(fontsel)); | |
155 | |
156 space = strrchr(fontname, ' '); | |
157 if(space && isdigit(*(space+1))) | |
158 *space = '\0'; | |
159 | |
160 gtk_imhtml_toggle_fontface(GTK_IMHTML(toolbar->imhtml), fontname); | |
161 | |
162 g_free(fontname); | |
163 | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
164 cancel_toolbar_font(NULL, toolbar); |
8317 | 165 } |
166 | |
167 static void | |
168 toggle_font(GtkWidget *font, GtkIMHtmlToolbar *toolbar) | |
169 { | |
9025 | 170 const char *fontname; |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
171 |
8317 | 172 g_return_if_fail(toolbar); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
173 |
9025 | 174 fontname = gtk_imhtml_get_current_fontface(GTK_IMHTML(toolbar->imhtml)); |
175 | |
8317 | 176 if (!toolbar->font_dialog) { |
177 toolbar->font_dialog = gtk_font_selection_dialog_new(_("Select Font")); | |
178 | |
179 g_object_set_data(G_OBJECT(toolbar->font_dialog), "gaim_toolbar", toolbar); | |
10134 | 180 |
9025 | 181 if(fontname) { |
182 char fonttif[128]; | |
183 g_snprintf(fonttif, sizeof(fonttif), "%s 12", fontname); | |
184 gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(toolbar->font_dialog), | |
185 fonttif); | |
186 } else { | |
187 gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(toolbar->font_dialog), | |
188 DEFAULT_FONT_FACE); | |
189 } | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
190 |
8317 | 191 g_signal_connect(G_OBJECT(toolbar->font_dialog), "delete_event", |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
192 G_CALLBACK(destroy_toolbar_font), toolbar); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
193 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
|
194 G_CALLBACK(apply_font), toolbar->font_dialog); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
195 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
|
196 G_CALLBACK(cancel_toolbar_font), toolbar); |
10125 | 197 g_signal_connect_after(G_OBJECT(toolbar->font_dialog), "realize", |
198 G_CALLBACK(realize_toolbar_font), toolbar); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
199 |
8317 | 200 gtk_window_present(GTK_WINDOW(toolbar->font_dialog)); |
201 } else { | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
202 cancel_toolbar_font(NULL, toolbar); |
8317 | 203 } |
204 gtk_widget_grab_focus(toolbar->imhtml); | |
205 } | |
206 | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
207 static void |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
208 destroy_toolbar_fgcolor(GtkWidget *widget, GdkEvent *event, |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
209 GtkIMHtmlToolbar *toolbar) |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
210 { |
10135 | 211 if (widget != NULL) |
212 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->fgcolor), FALSE); | |
8324
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 if (toolbar->fgcolor_dialog != NULL) |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
215 { |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
216 gtk_widget_destroy(toolbar->fgcolor_dialog); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
217 toolbar->fgcolor_dialog = NULL; |
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 } |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
220 |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
221 static void cancel_toolbar_fgcolor(GtkWidget *widget, |
8321
eb269b81fff8
[gaim-migrate @ 9045]
Christian Hammond <chipx86@chipx86.com>
parents:
8320
diff
changeset
|
222 GtkIMHtmlToolbar *toolbar) |
8317 | 223 { |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
224 destroy_toolbar_fgcolor(widget, NULL, toolbar); |
8317 | 225 } |
226 | |
227 static void do_fgcolor(GtkWidget *widget, GtkColorSelection *colorsel) | |
228 { | |
229 GdkColor text_color; | |
230 GtkIMHtmlToolbar *toolbar = g_object_get_data(G_OBJECT(colorsel), "gaim_toolbar"); | |
231 char *open_tag; | |
232 | |
233 open_tag = g_malloc(30); | |
234 gtk_color_selection_get_current_color(colorsel, &text_color); | |
235 g_snprintf(open_tag, 23, "#%02X%02X%02X", | |
236 text_color.red / 256, | |
237 text_color.green / 256, | |
238 text_color.blue / 256); | |
239 gtk_imhtml_toggle_forecolor(GTK_IMHTML(toolbar->imhtml), open_tag); | |
240 | |
241 g_free(open_tag); | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
242 cancel_toolbar_fgcolor(NULL, toolbar); |
8317 | 243 } |
244 | |
245 static void | |
246 toggle_fg_color(GtkWidget *color, GtkIMHtmlToolbar *toolbar) | |
247 { | |
248 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(color))) { | |
249 GtkWidget *colorsel; | |
9025 | 250 GdkColor fgcolor; |
251 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
|
252 |
8317 | 253 if (!toolbar->fgcolor_dialog) { |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
254 |
8317 | 255 toolbar->fgcolor_dialog = gtk_color_selection_dialog_new(_("Select Text Color")); |
256 colorsel = GTK_COLOR_SELECTION_DIALOG(toolbar->fgcolor_dialog)->colorsel; | |
9025 | 257 if (color) { |
258 gdk_color_parse(color, &fgcolor); | |
259 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel), &fgcolor); | |
260 } | |
261 | |
8317 | 262 g_object_set_data(G_OBJECT(colorsel), "gaim_toolbar", toolbar); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
263 |
8317 | 264 g_signal_connect(G_OBJECT(toolbar->fgcolor_dialog), "delete_event", |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
265 G_CALLBACK(destroy_toolbar_fgcolor), toolbar); |
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)->ok_button), "clicked", |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
267 G_CALLBACK(do_fgcolor), colorsel); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
268 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
|
269 G_CALLBACK(cancel_toolbar_fgcolor), toolbar); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
270 |
8317 | 271 } |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
272 gtk_window_present(GTK_WINDOW(toolbar->fgcolor_dialog)); |
8317 | 273 } else if (toolbar->fgcolor_dialog != NULL) { |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
274 cancel_toolbar_fgcolor(color, toolbar); |
8317 | 275 } else { |
9863 | 276 /* gaim_gtk_advance_past(gtkconv, "<FONT COLOR>", "</FONT>"); */ |
8317 | 277 } |
278 gtk_widget_grab_focus(toolbar->imhtml); | |
279 } | |
280 | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
281 static void |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
282 destroy_toolbar_bgcolor(GtkWidget *widget, GdkEvent *event, |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
283 GtkIMHtmlToolbar *toolbar) |
8317 | 284 { |
10135 | 285 if (widget != NULL) |
286 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
|
287 |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
288 if (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 gtk_widget_destroy(toolbar->bgcolor_dialog); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
291 toolbar->bgcolor_dialog = NULL; |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
292 } |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
293 } |
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 static void |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
296 cancel_toolbar_bgcolor(GtkWidget *widget, GtkIMHtmlToolbar *toolbar) |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
297 { |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
298 destroy_toolbar_bgcolor(widget, NULL, toolbar); |
8317 | 299 } |
300 | |
301 static void do_bgcolor(GtkWidget *widget, GtkColorSelection *colorsel) | |
302 { | |
303 GdkColor text_color; | |
304 GtkIMHtmlToolbar *toolbar = g_object_get_data(G_OBJECT(colorsel), "gaim_toolbar"); | |
305 char *open_tag; | |
306 | |
307 open_tag = g_malloc(30); | |
308 gtk_color_selection_get_current_color(colorsel, &text_color); | |
309 g_snprintf(open_tag, 23, "#%02X%02X%02X", | |
310 text_color.red / 256, | |
311 text_color.green / 256, | |
312 text_color.blue / 256); | |
313 gtk_imhtml_toggle_backcolor(GTK_IMHTML(toolbar->imhtml), open_tag); | |
314 | |
315 g_free(open_tag); | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
316 cancel_toolbar_bgcolor(NULL, toolbar); |
8317 | 317 } |
318 | |
319 static void | |
320 toggle_bg_color(GtkWidget *color, GtkIMHtmlToolbar *toolbar) | |
321 { | |
322 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(color))) { | |
323 GtkWidget *colorsel; | |
9025 | 324 GdkColor bgcolor; |
325 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
|
326 |
8317 | 327 if (!toolbar->bgcolor_dialog) { |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
328 |
8359 | 329 toolbar->bgcolor_dialog = gtk_color_selection_dialog_new(_("Select Background Color")); |
8317 | 330 colorsel = GTK_COLOR_SELECTION_DIALOG(toolbar->bgcolor_dialog)->colorsel; |
9025 | 331 if (color) { |
332 gdk_color_parse(color, &bgcolor); | |
333 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel), &bgcolor); | |
334 } | |
335 | |
8317 | 336 g_object_set_data(G_OBJECT(colorsel), "gaim_toolbar", toolbar); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
337 |
8317 | 338 g_signal_connect(G_OBJECT(toolbar->bgcolor_dialog), "delete_event", |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
339 G_CALLBACK(destroy_toolbar_bgcolor), toolbar); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
340 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
|
341 G_CALLBACK(do_bgcolor), colorsel); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
342 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
|
343 G_CALLBACK(cancel_toolbar_bgcolor), toolbar); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
344 |
8317 | 345 } |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
346 gtk_window_present(GTK_WINDOW(toolbar->bgcolor_dialog)); |
8317 | 347 } else if (toolbar->bgcolor_dialog != NULL) { |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
348 cancel_toolbar_bgcolor(color, toolbar); |
8317 | 349 } else { |
9863 | 350 /* gaim_gtk_advance_past(gtkconv, "<FONT COLOR>", "</FONT>"); */ |
8317 | 351 } |
352 gtk_widget_grab_focus(toolbar->imhtml); | |
353 } | |
354 | |
355 static void | |
356 cancel_link_cb(GtkIMHtmlToolbar *toolbar, GaimRequestFields *fields) | |
357 { | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
358 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
|
359 |
8317 | 360 toolbar->link_dialog = NULL; |
361 } | |
362 | |
363 static void | |
364 close_link_dialog(GtkIMHtmlToolbar *toolbar) | |
365 { | |
366 if (toolbar->link_dialog != NULL) | |
367 { | |
368 gaim_request_close(GAIM_REQUEST_FIELDS, toolbar->link_dialog); | |
369 toolbar->link_dialog = NULL; | |
370 } | |
371 } | |
372 | |
373 static void | |
374 do_insert_link_cb(GtkIMHtmlToolbar *toolbar, GaimRequestFields *fields) | |
375 { | |
376 const char *url, *description; | |
377 | |
378 url = gaim_request_fields_get_string(fields, "url"); | |
9041 | 379 if (GTK_IMHTML(toolbar->imhtml)->format_functions & GTK_IMHTML_LINKDESC) |
380 description = gaim_request_fields_get_string(fields, "description"); | |
381 else | |
382 description = NULL; | |
8317 | 383 |
384 if (description == NULL) | |
385 description = url; | |
386 | |
8677 | 387 gtk_imhtml_insert_link(GTK_IMHTML(toolbar->imhtml), |
388 gtk_text_buffer_get_insert(GTK_IMHTML(toolbar->imhtml)->text_buffer), | |
389 url, description); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
390 |
8317 | 391 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->link), FALSE); |
392 | |
393 toolbar->link_dialog = NULL; | |
394 } | |
395 | |
396 static void | |
397 insert_link_cb(GtkWidget *w, GtkIMHtmlToolbar *toolbar) | |
398 { | |
399 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->link))) { | |
400 GaimRequestFields *fields; | |
401 GaimRequestFieldGroup *group; | |
402 GaimRequestField *field; | |
9599 | 403 GtkTextIter start, end; |
9041 | 404 char *msg; |
9599 | 405 char *desc = NULL; |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
406 |
8317 | 407 fields = gaim_request_fields_new(); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
408 |
8317 | 409 group = gaim_request_field_group_new(NULL); |
410 gaim_request_fields_add_group(fields, group); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
411 |
8317 | 412 field = gaim_request_field_string_new("url", _("_URL"), NULL, FALSE); |
413 gaim_request_field_set_required(field, TRUE); | |
414 gaim_request_field_group_add_field(group, field); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
415 |
9041 | 416 if(GTK_IMHTML(toolbar->imhtml)->format_functions & GTK_IMHTML_LINKDESC) { |
9599 | 417 if (gtk_text_buffer_get_selection_bounds(GTK_IMHTML(toolbar->imhtml)->text_buffer, &start, &end)) { |
418 desc = gtk_imhtml_get_text(GTK_IMHTML(toolbar->imhtml), &start, &end); | |
419 } | |
9041 | 420 field = gaim_request_field_string_new("description", _("_Description"), |
9599 | 421 desc, FALSE); |
9041 | 422 gaim_request_field_group_add_field(group, field); |
423 msg = g_strdup(_("Please enter the URL and description of the " | |
424 "link that you want to insert. The description " | |
425 "is optional.")); | |
426 } else { | |
427 msg = g_strdup(_("Please enter the URL of the " | |
428 "link that you want to insert.")); | |
429 } | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
430 |
8317 | 431 toolbar->link_dialog = |
432 gaim_request_fields(toolbar, _("Insert Link"), | |
433 NULL, | |
9041 | 434 msg, |
8317 | 435 fields, |
436 _("_Insert"), G_CALLBACK(do_insert_link_cb), | |
437 _("Cancel"), G_CALLBACK(cancel_link_cb), | |
438 toolbar); | |
9041 | 439 g_free(msg); |
9599 | 440 g_free(desc); |
8322
ffb601c6b833
[gaim-migrate @ 9046]
Christian Hammond <chipx86@chipx86.com>
parents:
8321
diff
changeset
|
441 } else { |
8317 | 442 close_link_dialog(toolbar); |
443 } | |
444 gtk_widget_grab_focus(toolbar->imhtml); | |
445 } | |
446 | |
447 | |
448 static void | |
9522 | 449 do_insert_image_cb(GtkWidget *widget, int response, GtkIMHtmlToolbar *toolbar) |
8317 | 450 { |
9522 | 451 gchar *filename, *name, *buf; |
452 char *filedata; | |
8317 | 453 size_t size; |
454 GError *error = NULL; | |
455 int id; | |
8962 | 456 GtkTextIter iter; |
457 GtkTextMark *ins; | |
8317 | 458 |
9522 | 459 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
460 if (response != GTK_RESPONSE_ACCEPT) { | |
461 #else /* FILECHOOSER */ | |
462 if (response != GTK_RESPONSE_OK) { | |
463 #endif /* FILECHOOSER */ | |
8317 | 464 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->image), FALSE); |
465 return; | |
466 } | |
467 | |
9522 | 468 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
469 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget)); | |
470 #else /* FILECHOOSER */ | |
471 filename = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(widget))); | |
472 #endif /* FILECHOOSER */ | |
8317 | 473 |
9522 | 474 if (filename == NULL) { |
8317 | 475 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->image), FALSE); |
476 return; | |
477 } | |
478 | |
9522 | 479 #if !GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
480 if (gaim_gtk_check_if_dir(filename, GTK_FILE_SELECTION(widget))) { | |
481 g_free(filename); | |
482 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->image), FALSE); | |
483 return; | |
484 } | |
485 #endif /* FILECHOOSER */ | |
486 | |
487 /* The following triggers a callback that closes the widget */ | |
8317 | 488 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->image), FALSE); |
489 | |
9522 | 490 if (!g_file_get_contents(filename, &filedata, &size, &error)) { |
8317 | 491 gaim_notify_error(NULL, NULL, error->message, NULL); |
492 | |
493 g_error_free(error); | |
9522 | 494 g_free(filename); |
8317 | 495 |
496 return; | |
497 } | |
498 | |
9522 | 499 name = strrchr(filename, G_DIR_SEPARATOR) + 1; |
8317 | 500 |
9522 | 501 id = gaim_imgstore_add(filedata, size, name); |
8317 | 502 g_free(filedata); |
503 | |
9522 | 504 if (id == 0) { |
505 buf = g_strdup_printf(_("Failed to store image: %s\n"), filename); | |
8317 | 506 gaim_notify_error(NULL, NULL, buf, NULL); |
507 | |
508 g_free(buf); | |
9522 | 509 g_free(filename); |
8317 | 510 |
511 return; | |
512 } | |
513 | |
9522 | 514 g_free(filename); |
515 | |
8962 | 516 ins = gtk_text_buffer_get_insert(gtk_text_view_get_buffer(GTK_TEXT_VIEW(toolbar->imhtml))); |
517 gtk_text_buffer_get_iter_at_mark(gtk_text_view_get_buffer(GTK_TEXT_VIEW(toolbar->imhtml)), | |
9522 | 518 &iter, ins); |
8962 | 519 gtk_imhtml_insert_image_at_iter(GTK_IMHTML(toolbar->imhtml), id, &iter); |
520 gaim_imgstore_unref(id); | |
8317 | 521 } |
522 | |
523 | |
524 static void | |
525 insert_image_cb(GtkWidget *save, GtkIMHtmlToolbar *toolbar) | |
526 { | |
527 GtkWidget *window; | |
528 | |
529 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->image))) { | |
9522 | 530 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
531 window = gtk_file_chooser_dialog_new(_("Insert Image"), | |
532 NULL, | |
533 GTK_FILE_CHOOSER_ACTION_OPEN, | |
534 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | |
535 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, | |
536 NULL); | |
537 gtk_dialog_set_default_response(GTK_DIALOG(window), GTK_RESPONSE_ACCEPT); | |
538 g_signal_connect(G_OBJECT(GTK_FILE_CHOOSER(window)), | |
539 "response", G_CALLBACK(do_insert_image_cb), toolbar); | |
540 #else /* FILECHOOSER */ | |
8317 | 541 window = gtk_file_selection_new(_("Insert Image")); |
542 gtk_dialog_set_default_response(GTK_DIALOG(window), GTK_RESPONSE_OK); | |
543 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(window)), | |
544 "response", G_CALLBACK(do_insert_image_cb), toolbar); | |
9522 | 545 #endif /* FILECHOOSER */ |
8317 | 546 |
547 gtk_widget_show(window); | |
548 toolbar->image_dialog = window; | |
549 } else { | |
550 gtk_widget_destroy(toolbar->image_dialog); | |
551 toolbar->image_dialog = NULL; | |
552 } | |
9522 | 553 |
8317 | 554 gtk_widget_grab_focus(toolbar->imhtml); |
555 } | |
556 | |
10138 | 557 #if GTK_CHECK_VERSION(2,4,0) /* Smiley selection menu */ |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
558 static void |
10138 | 559 smiley_dialog_closed_cb(GtkWidget *widget, GtkIMHtmlToolbar *toolbar) |
8317 | 560 { |
10138 | 561 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->smiley), FALSE); |
562 } | |
563 #else | |
564 static void | |
565 destroy_smiley_dialog(GtkIMHtmlToolbar *toolbar) | |
566 { | |
567 if (toolbar->smiley_dialog != NULL) | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
568 { |
10138 | 569 gtk_widget_destroy(toolbar->smiley_dialog); |
570 toolbar->smiley_dialog = NULL; | |
8317 | 571 } |
572 } | |
573 | |
10134 | 574 static void |
10138 | 575 close_smiley_dialog(GtkWidget *widget, GdkEvent *event, |
576 GtkIMHtmlToolbar *toolbar) | |
10134 | 577 { |
578 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->smiley), FALSE); | |
579 } | |
10138 | 580 #endif |
8317 | 581 |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
582 static void |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
583 insert_smiley_text(GtkWidget *widget, GtkIMHtmlToolbar *toolbar) |
8317 | 584 { |
9027 | 585 char *smiley_text, *escaped_smiley; |
586 | |
587 smiley_text = g_object_get_data(G_OBJECT(widget), "smiley_text"); | |
588 escaped_smiley = gaim_escape_html(smiley_text); | |
8317 | 589 |
8456 | 590 gtk_imhtml_insert_smiley(GTK_IMHTML(toolbar->imhtml), |
591 GTK_IMHTML(toolbar->imhtml)->protocol_name, | |
9027 | 592 escaped_smiley); |
8317 | 593 |
9027 | 594 g_free(escaped_smiley); |
10138 | 595 |
596 #if !GTK_CHECK_VERSION(2,4,0) /* Smiley selection menu */ | |
597 close_smiley_dialog(NULL, NULL, toolbar); | |
598 #endif | |
8317 | 599 } |
600 | |
10138 | 601 #if GTK_CHECK_VERSION(2,4,0) /* Smiley selection menu */ |
602 static void | |
603 add_smiley(GtkIMHtmlToolbar *toolbar, GtkWidget *menu, int row, int col, char *filename, char *face) | |
8317 | 604 { |
605 GtkWidget *image; | |
10134 | 606 GtkWidget *menuitem; |
8317 | 607 |
608 image = gtk_image_new_from_file(filename); | |
10134 | 609 menuitem = gtk_image_menu_item_new_with_label(""); |
610 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); | |
611 g_object_set_data(G_OBJECT(menuitem), "smiley_text", face); | |
612 gtk_tooltips_set_tip(toolbar->tooltips, menuitem, face, NULL); | |
613 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(insert_smiley_text), toolbar); | |
614 gtk_menu_attach(GTK_MENU(menu), menuitem, col, col+1, row, row+1); | |
8317 | 615 } |
10138 | 616 #else |
617 static void | |
618 add_smiley(GtkIMHtmlToolbar *toolbar, GtkWidget *table, int row, int col, char *filename, char *face) | |
619 { | |
620 GtkWidget *image; | |
621 GtkWidget *button; | |
8317 | 622 |
10138 | 623 image = gtk_image_new_from_file(filename); |
624 button = gtk_button_new(); | |
625 gtk_container_add(GTK_CONTAINER(button), image); | |
626 g_object_set_data(G_OBJECT(button), "smiley_text", face); | |
627 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(insert_smiley_text), toolbar); | |
628 | |
629 gtk_tooltips_set_tip(toolbar->tooltips, button, face, NULL); | |
630 | |
631 gtk_table_attach_defaults(GTK_TABLE(table), button, col, col+1, row, row+1); | |
632 | |
633 /* these look really weird with borders */ | |
634 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
635 | |
636 gtk_widget_show(button); | |
637 } | |
638 #endif | |
639 | |
640 static gboolean | |
641 smiley_is_unique(GSList *list, GtkIMHtmlSmiley *smiley) { | |
8317 | 642 while(list) { |
643 GtkIMHtmlSmiley *cur = list->data; | |
644 if(!strcmp(cur->file, smiley->file)) | |
645 return FALSE; | |
646 list = list->next; | |
647 } | |
648 return TRUE; | |
649 } | |
650 | |
651 | |
10138 | 652 #if GTK_CHECK_VERSION(2,4,0) /* Smiley selection menu */ |
8317 | 653 static void |
654 insert_smiley_cb(GtkWidget *smiley, GtkIMHtmlToolbar *toolbar) | |
655 { | |
10134 | 656 GtkWidget *menu; |
657 GSList *smileys, *unique_smileys = NULL; | |
658 int width; | |
659 int row = 0, col = 0; | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
660 |
10138 | 661 if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(smiley))) |
662 return; | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
663 |
10134 | 664 if (toolbar->sml) |
665 smileys = get_proto_smileys(toolbar->sml); | |
666 else | |
667 smileys = get_proto_smileys(NULL); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
668 |
10134 | 669 while(smileys) { |
670 GtkIMHtmlSmiley *smiley = smileys->data; | |
671 if(!smiley->hidden) { | |
672 if(smiley_is_unique(unique_smileys, smiley)) | |
673 unique_smileys = g_slist_append(unique_smileys, smiley); | |
8317 | 674 } |
10134 | 675 smileys = smileys->next; |
676 } | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
677 |
10134 | 678 menu = gtk_menu_new(); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
679 |
10134 | 680 if(g_slist_length(unique_smileys)) { |
8892 | 681 |
10134 | 682 width = floor(sqrt(g_slist_length(unique_smileys))); |
8892 | 683 |
10134 | 684 /* build menu */ |
685 while(unique_smileys) { | |
686 GtkIMHtmlSmiley *smiley = unique_smileys->data; | |
687 if(!smiley->hidden) { | |
688 add_smiley(toolbar, menu, row, col, smiley->file, smiley->smile); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
689 |
10134 | 690 if(++col >= width) { |
691 col = 0; | |
692 row++; | |
693 } | |
694 } | |
695 unique_smileys = unique_smileys->next; | |
696 } | |
697 } | |
698 else { | |
699 GtkWidget *menuitem; | |
700 menuitem = gtk_menu_item_new_with_label(_("This theme has no available smileys.")); | |
701 gtk_widget_set_sensitive(menuitem, FALSE); | |
702 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
703 } | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
704 |
10138 | 705 /* |
706 * The menu itself is free'd automatically, but we need to un-press | |
707 * the "insert smiley" button whenever the menu is closed. | |
708 * | |
709 * XXX - Make sure the menu really is freed! | |
710 */ | |
10134 | 711 g_signal_connect(G_OBJECT(menu), "deactivate", |
10138 | 712 G_CALLBACK(smiley_dialog_closed_cb), toolbar); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
713 |
10134 | 714 /* show everything */ |
715 gtk_widget_show_all(menu); | |
716 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time()); | |
10138 | 717 toolbar->smiley_dialog = menu; |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
718 |
8317 | 719 gtk_widget_grab_focus(toolbar->imhtml); |
720 } | |
10138 | 721 #else |
722 static void | |
723 insert_smiley_cb(GtkWidget *smiley, GtkIMHtmlToolbar *toolbar) | |
724 { | |
725 GtkWidget *dialog; | |
726 GtkWidget *smiley_table = NULL; | |
727 GSList *smileys, *unique_smileys = NULL; | |
728 int width; | |
729 int row = 0, col = 0; | |
730 | |
731 if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(smiley))) { | |
732 destroy_smiley_dialog(toolbar); | |
733 gtk_widget_grab_focus(toolbar->imhtml); | |
734 return; | |
735 } | |
736 | |
737 if (toolbar->sml) | |
738 smileys = get_proto_smileys(toolbar->sml); | |
739 else | |
740 smileys = get_proto_smileys(NULL); | |
741 | |
742 while(smileys) { | |
743 GtkIMHtmlSmiley *smiley = smileys->data; | |
744 if(!smiley->hidden) { | |
745 if(smiley_is_unique(unique_smileys, smiley)) | |
746 unique_smileys = g_slist_append(unique_smileys, smiley); | |
747 } | |
748 smileys = smileys->next; | |
749 } | |
750 | |
751 GAIM_DIALOG(dialog); | |
752 | |
753 gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); | |
754 gtk_window_set_role(GTK_WINDOW(dialog), "smiley_dialog"); | |
755 gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_MOUSE); | |
756 | |
757 if(g_slist_length(unique_smileys)) { | |
758 | |
759 width = floor(sqrt(g_slist_length(unique_smileys))); | |
760 | |
761 smiley_table = gtk_table_new(width, width, TRUE); | |
762 | |
763 /* pack buttons */ | |
764 | |
765 while(unique_smileys) { | |
766 GtkIMHtmlSmiley *smiley = unique_smileys->data; | |
767 if(!smiley->hidden) { | |
768 add_smiley(toolbar, smiley_table, row, col, smiley->file, smiley->smile); | |
769 if(++col >= width) { | |
770 col = 0; | |
771 row++; | |
772 } | |
773 } | |
774 unique_smileys = unique_smileys->next; | |
775 } | |
776 } | |
777 else { | |
778 smiley_table = gtk_label_new(_("This theme has no available smileys.")); | |
779 } | |
780 | |
781 gtk_container_add(GTK_CONTAINER(dialog), smiley_table); | |
782 | |
783 gtk_widget_show(smiley_table); | |
784 | |
785 gtk_container_set_border_width(GTK_CONTAINER(dialog), 5); | |
786 | |
787 /* connect signals */ | |
788 g_signal_connect(G_OBJECT(dialog), "delete_event", | |
789 G_CALLBACK(close_smiley_dialog), toolbar); | |
790 | |
791 /* show everything */ | |
792 gtk_window_set_title(GTK_WINDOW(dialog), _("Smile!")); | |
793 gtk_widget_show_all(dialog); | |
794 | |
795 toolbar->smiley_dialog = dialog; | |
796 | |
797 gtk_widget_grab_focus(toolbar->imhtml); | |
798 } | |
799 #endif | |
8317 | 800 |
8420 | 801 static void update_buttons_cb(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons, GtkIMHtmlToolbar *toolbar) |
802 { | |
803 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->bold), buttons & GTK_IMHTML_BOLD); | |
804 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->italic), buttons & GTK_IMHTML_ITALIC); | |
805 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->underline), buttons & GTK_IMHTML_UNDERLINE); | |
806 | |
807 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->larger_size), buttons & GTK_IMHTML_GROW); | |
808 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->smaller_size), buttons & GTK_IMHTML_SHRINK); | |
809 | |
810 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->font), buttons & GTK_IMHTML_FACE); | |
811 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->fgcolor), buttons & GTK_IMHTML_FORECOLOR); | |
812 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->bgcolor), buttons & GTK_IMHTML_BACKCOLOR); | |
813 | |
814 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->image), buttons & GTK_IMHTML_IMAGE); | |
815 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->link), buttons & GTK_IMHTML_LINK); | |
816 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->smiley), buttons & GTK_IMHTML_SMILEY); | |
8481 | 817 } |
8420 | 818 |
8481 | 819 /* we call this when we want to _set_active the toggle button, it'll |
820 * block the callback thats connected to the button so we don't have to | |
821 * do the double toggling hack | |
822 */ | |
823 static void toggle_button_set_active_block(GtkToggleButton *button, | |
824 gboolean is_active, | |
825 GtkIMHtmlToolbar *toolbar) | |
826 { | |
827 GObject *object; | |
828 g_return_if_fail(toolbar); | |
829 | |
830 object = g_object_ref(button); | |
831 g_signal_handlers_block_matched(object, G_SIGNAL_MATCH_DATA, | |
832 0, 0, NULL, NULL, toolbar); | |
833 gtk_toggle_button_set_active(button, is_active); | |
834 g_signal_handlers_unblock_matched(object, G_SIGNAL_MATCH_DATA, | |
835 0, 0, NULL, NULL, toolbar); | |
836 g_object_unref(object); | |
8420 | 837 } |
838 | |
839 static void toggle_button_cb(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons, GtkIMHtmlToolbar *toolbar) | |
840 { | |
8481 | 841 if (buttons & GTK_IMHTML_BOLD) |
842 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->bold), | |
843 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->bold)), | |
844 toolbar); | |
8420 | 845 |
8481 | 846 if (buttons & GTK_IMHTML_ITALIC) |
847 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->italic), | |
848 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->italic)), | |
849 toolbar); | |
8420 | 850 |
8481 | 851 if (buttons & GTK_IMHTML_UNDERLINE) |
852 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->underline), | |
853 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->underline)), | |
854 toolbar); | |
8420 | 855 } |
856 | |
8427 | 857 static void reset_buttons_cb(GtkIMHtml *imhtml, GtkIMHtmlToolbar *toolbar) |
858 { | |
8481 | 859 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->bold))) |
860 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->bold), FALSE, | |
861 toolbar); | |
10134 | 862 |
8481 | 863 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->italic))) |
864 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->italic), | |
865 FALSE, toolbar); | |
10134 | 866 |
8481 | 867 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->underline))) |
868 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->underline), | |
869 FALSE, toolbar); | |
870 } | |
8516 | 871 |
872 static void update_buttons(GtkIMHtmlToolbar *toolbar) { | |
8506 | 873 gboolean bold, italic, underline; |
10134 | 874 |
8506 | 875 bold = italic = underline = FALSE; |
8516 | 876 gtk_imhtml_get_current_format(GTK_IMHTML(toolbar->imhtml), |
877 &bold, &italic, &underline); | |
8506 | 878 |
879 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->bold)) != bold) | |
880 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->bold), bold, | |
881 toolbar); | |
8516 | 882 |
8506 | 883 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->italic)) != italic) |
884 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->italic), italic, | |
885 toolbar); | |
8516 | 886 |
8506 | 887 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->underline)) != underline) |
888 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->underline), | |
8677 | 889 underline, toolbar); |
8506 | 890 } |
8481 | 891 |
8516 | 892 static void update_format_cb(GtkIMHtml *imhtml, GtkIMHtmlToolbar *toolbar) { |
893 update_buttons(toolbar); | |
894 } | |
8481 | 895 |
8516 | 896 static void mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *location, |
897 GtkTextMark *mark, GtkIMHtmlToolbar *toolbar) | |
898 { | |
899 if(mark != gtk_text_buffer_get_insert(buffer)) | |
900 return; | |
901 | |
902 update_buttons(toolbar); | |
8427 | 903 } |
904 | |
8317 | 905 enum { |
906 LAST_SIGNAL | |
907 }; | |
9863 | 908 /* static guint signals [LAST_SIGNAL] = { 0 }; */ |
8317 | 909 |
910 static void | |
911 gtk_imhtmltoolbar_finalize (GObject *object) | |
912 { | |
8391 | 913 GtkIMHtmlToolbar *toolbar = GTK_IMHTMLTOOLBAR(object); |
8317 | 914 |
8685
2ac2f4cf1de5
[gaim-migrate @ 9438]
Christian Hammond <chipx86@chipx86.com>
parents:
8677
diff
changeset
|
915 if (toolbar->image_dialog != NULL) |
2ac2f4cf1de5
[gaim-migrate @ 9438]
Christian Hammond <chipx86@chipx86.com>
parents:
8677
diff
changeset
|
916 { |
2ac2f4cf1de5
[gaim-migrate @ 9438]
Christian Hammond <chipx86@chipx86.com>
parents:
8677
diff
changeset
|
917 gtk_widget_destroy(toolbar->image_dialog); |
2ac2f4cf1de5
[gaim-migrate @ 9438]
Christian Hammond <chipx86@chipx86.com>
parents:
8677
diff
changeset
|
918 toolbar->image_dialog = NULL; |
2ac2f4cf1de5
[gaim-migrate @ 9438]
Christian Hammond <chipx86@chipx86.com>
parents:
8677
diff
changeset
|
919 } |
2ac2f4cf1de5
[gaim-migrate @ 9438]
Christian Hammond <chipx86@chipx86.com>
parents:
8677
diff
changeset
|
920 |
10134 | 921 destroy_toolbar_font(NULL, NULL, toolbar); |
10138 | 922 #if !GTK_CHECK_VERSION(2,4,0) /* Smiley selection menu */ |
923 destroy_smiley_dialog(toolbar); | |
924 #endif | |
10134 | 925 destroy_toolbar_bgcolor(NULL, NULL, toolbar); |
926 destroy_toolbar_fgcolor(NULL, NULL, toolbar); | |
927 close_link_dialog(toolbar); | |
8784
48dd097eb475
[gaim-migrate @ 9546]
Christian Hammond <chipx86@chipx86.com>
parents:
8756
diff
changeset
|
928 |
8427 | 929 if (toolbar->sml) |
930 free(toolbar->sml); | |
8391 | 931 gtk_object_sink(GTK_OBJECT(toolbar->tooltips)); |
8317 | 932 |
8391 | 933 G_OBJECT_CLASS(parent_class)->finalize (object); |
8317 | 934 } |
935 | |
936 /* Boring GTK stuff */ | |
937 static void gtk_imhtmltoolbar_class_init (GtkIMHtmlToolbarClass *class) | |
938 { | |
939 GtkObjectClass *object_class; | |
940 GObjectClass *gobject_class; | |
941 object_class = (GtkObjectClass*) class; | |
942 gobject_class = (GObjectClass*) class; | |
10080 | 943 parent_class = gtk_type_class(GTK_TYPE_HBOX); |
8317 | 944 gobject_class->finalize = gtk_imhtmltoolbar_finalize; |
945 } | |
946 | |
947 static void gtk_imhtmltoolbar_init (GtkIMHtmlToolbar *toolbar) | |
948 { | |
10085 | 949 GtkWidget *hbox = GTK_WIDGET(toolbar); |
8317 | 950 GtkWidget *button; |
951 GtkWidget *sep; | |
952 GtkSizeGroup *sg; | |
953 | |
954 toolbar->imhtml = NULL; | |
955 toolbar->font_dialog = NULL; | |
956 toolbar->fgcolor_dialog = NULL; | |
957 toolbar->bgcolor_dialog = NULL; | |
958 toolbar->link_dialog = NULL; | |
10138 | 959 toolbar->smiley_dialog = NULL; |
8317 | 960 toolbar->image_dialog = NULL; |
961 | |
962 toolbar->tooltips = gtk_tooltips_new(); | |
10134 | 963 |
10080 | 964 gtk_box_set_spacing(GTK_BOX(toolbar), 6); |
8317 | 965 sg = gtk_size_group_new(GTK_SIZE_GROUP_BOTH); |
966 | |
967 /* Bold */ | |
968 button = gaim_pixbuf_toolbar_button_from_stock(GTK_STOCK_BOLD); | |
969 gtk_size_group_add_widget(sg, button); | |
970 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
971 gtk_tooltips_set_tip(toolbar->tooltips, button, _("Bold"), NULL); | |
972 | |
973 g_signal_connect(G_OBJECT(button), "clicked", | |
974 G_CALLBACK(do_bold), toolbar); | |
975 | |
976 toolbar->bold = button; | |
977 | |
978 /* Italic */ | |
979 button = gaim_pixbuf_toolbar_button_from_stock(GTK_STOCK_ITALIC); | |
980 gtk_size_group_add_widget(sg, button); | |
981 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
982 gtk_tooltips_set_tip(toolbar->tooltips, button, _("Italic"), NULL); | |
983 | |
984 g_signal_connect(G_OBJECT(button), "clicked", | |
985 G_CALLBACK(do_italic), toolbar); | |
986 | |
987 toolbar->italic = button; | |
988 | |
989 /* Underline */ | |
990 button = gaim_pixbuf_toolbar_button_from_stock(GTK_STOCK_UNDERLINE); | |
991 gtk_size_group_add_widget(sg, button); | |
992 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
993 gtk_tooltips_set_tip(toolbar->tooltips, button, _("Underline"), NULL); | |
994 | |
995 g_signal_connect(G_OBJECT(button), "clicked", | |
996 G_CALLBACK(do_underline), toolbar); | |
997 | |
998 toolbar->underline = button; | |
999 | |
1000 /* Sep */ | |
1001 sep = gtk_vseparator_new(); | |
1002 gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0); | |
1003 | |
1004 /* Increase font size */ | |
1005 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_TEXT_BIGGER); | |
1006 gtk_size_group_add_widget(sg, button); | |
1007 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
1008 gtk_tooltips_set_tip(toolbar->tooltips, button, | |
1009 _("Larger font size"), NULL); | |
1010 | |
1011 g_signal_connect(G_OBJECT(button), "clicked", | |
1012 G_CALLBACK(do_big), toolbar); | |
1013 | |
1014 toolbar->larger_size = button; | |
1015 | |
1016 /* Decrease font size */ | |
1017 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_TEXT_SMALLER); | |
1018 gtk_size_group_add_widget(sg, button); | |
1019 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
1020 gtk_tooltips_set_tip(toolbar->tooltips, button, | |
1021 _("Smaller font size"), NULL); | |
1022 | |
1023 g_signal_connect(G_OBJECT(button), "clicked", | |
1024 G_CALLBACK(do_small), toolbar); | |
1025 | |
1026 toolbar->smaller_size = button; | |
1027 | |
1028 /* Sep */ | |
1029 sep = gtk_vseparator_new(); | |
1030 gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0); | |
1031 | |
1032 /* Font Face */ | |
1033 | |
1034 button = gaim_pixbuf_toolbar_button_from_stock(GTK_STOCK_SELECT_FONT); | |
1035 gtk_size_group_add_widget(sg, button); | |
1036 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
1037 gtk_tooltips_set_tip(toolbar->tooltips, button, | |
1038 _("Font Face"), NULL); | |
1039 | |
1040 g_signal_connect(G_OBJECT(button), "clicked", | |
1041 G_CALLBACK(toggle_font), toolbar); | |
1042 | |
1043 toolbar->font = button; | |
1044 | |
1045 /* Foreground Color */ | |
1046 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_FGCOLOR); | |
1047 gtk_size_group_add_widget(sg, button); | |
1048 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
1049 gtk_tooltips_set_tip(toolbar->tooltips, button, | |
1050 _("Foreground font color"), NULL); | |
1051 | |
1052 g_signal_connect(G_OBJECT(button), "clicked", | |
1053 G_CALLBACK(toggle_fg_color), toolbar); | |
1054 | |
1055 toolbar->fgcolor = button; | |
1056 | |
1057 /* Background Color */ | |
1058 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_BGCOLOR); | |
1059 gtk_size_group_add_widget(sg, button); | |
1060 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
1061 gtk_tooltips_set_tip(toolbar->tooltips, button, | |
1062 _("Background color"), NULL); | |
1063 | |
1064 g_signal_connect(G_OBJECT(button), "clicked", | |
1065 G_CALLBACK(toggle_bg_color), toolbar); | |
1066 | |
1067 toolbar->bgcolor = button; | |
1068 | |
1069 /* Sep */ | |
1070 sep = gtk_vseparator_new(); | |
1071 gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0); | |
1072 | |
1073 /* Insert Link */ | |
1074 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_LINK); | |
1075 gtk_size_group_add_widget(sg, button); | |
1076 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
1077 gtk_tooltips_set_tip(toolbar->tooltips, button, _("Insert link"), NULL); | |
1078 g_signal_connect(G_OBJECT(button), "clicked", | |
1079 G_CALLBACK(insert_link_cb), toolbar); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
1080 |
8317 | 1081 toolbar->link = button; |
1082 | |
1083 /* Insert IM Image */ | |
1084 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_IMAGE); | |
1085 gtk_size_group_add_widget(sg, button); | |
1086 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
1087 gtk_tooltips_set_tip(toolbar->tooltips, button, _("Insert image"), NULL); | |
1088 | |
1089 g_signal_connect(G_OBJECT(button), "clicked", | |
1090 G_CALLBACK(insert_image_cb), toolbar); | |
1091 | |
1092 toolbar->image = button; | |
1093 | |
1094 /* Insert Smiley */ | |
1095 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_SMILEY); | |
1096 gtk_size_group_add_widget(sg, button); | |
1097 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
1098 gtk_tooltips_set_tip(toolbar->tooltips, button, _("Insert smiley"), NULL); | |
1099 | |
10138 | 1100 g_signal_connect(G_OBJECT(button), "clicked", |
8317 | 1101 G_CALLBACK(insert_smiley_cb), toolbar); |
1102 | |
1103 toolbar->smiley = button; | |
1104 | |
8427 | 1105 toolbar->sml = NULL; |
8317 | 1106 gtk_widget_show_all(hbox); |
1107 } | |
1108 | |
1109 GtkWidget *gtk_imhtmltoolbar_new() | |
1110 { | |
1111 return GTK_WIDGET(g_object_new(gtk_imhtmltoolbar_get_type(), NULL)); | |
1112 } | |
1113 | |
1114 GType gtk_imhtmltoolbar_get_type() | |
1115 { | |
1116 static GType imhtmltoolbar_type = 0; | |
1117 | |
1118 if (!imhtmltoolbar_type) { | |
1119 static const GTypeInfo imhtmltoolbar_info = { | |
1120 sizeof(GtkIMHtmlToolbarClass), | |
1121 NULL, | |
1122 NULL, | |
1123 (GClassInitFunc) gtk_imhtmltoolbar_class_init, | |
1124 NULL, | |
1125 NULL, | |
1126 sizeof (GtkIMHtmlToolbar), | |
1127 0, | |
1128 (GInstanceInitFunc) gtk_imhtmltoolbar_init | |
1129 }; | |
1130 | |
10080 | 1131 imhtmltoolbar_type = g_type_register_static(GTK_TYPE_HBOX, |
8317 | 1132 "GtkIMHtmlToolbar", &imhtmltoolbar_info, 0); |
1133 } | |
1134 | |
1135 return imhtmltoolbar_type; | |
1136 } | |
1137 | |
1138 | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
1139 void gtk_imhtmltoolbar_attach(GtkIMHtmlToolbar *toolbar, GtkWidget *imhtml) |
8317 | 1140 { |
8788 | 1141 GtkIMHtmlButtons buttons; |
8481 | 1142 gboolean bold, italic, underline; |
1143 | |
8325
415283e39bce
[gaim-migrate @ 9049]
Christian Hammond <chipx86@chipx86.com>
parents:
8324
diff
changeset
|
1144 g_return_if_fail(toolbar != NULL); |
415283e39bce
[gaim-migrate @ 9049]
Christian Hammond <chipx86@chipx86.com>
parents:
8324
diff
changeset
|
1145 g_return_if_fail(GTK_IS_IMHTMLTOOLBAR(toolbar)); |
415283e39bce
[gaim-migrate @ 9049]
Christian Hammond <chipx86@chipx86.com>
parents:
8324
diff
changeset
|
1146 g_return_if_fail(imhtml != NULL); |
415283e39bce
[gaim-migrate @ 9049]
Christian Hammond <chipx86@chipx86.com>
parents:
8324
diff
changeset
|
1147 g_return_if_fail(GTK_IS_IMHTML(imhtml)); |
415283e39bce
[gaim-migrate @ 9049]
Christian Hammond <chipx86@chipx86.com>
parents:
8324
diff
changeset
|
1148 |
8317 | 1149 toolbar->imhtml = imhtml; |
8506 | 1150 g_signal_connect(G_OBJECT(imhtml), "format_buttons_update", G_CALLBACK(update_buttons_cb), toolbar); |
8420 | 1151 g_signal_connect(G_OBJECT(imhtml), "format_function_toggle", G_CALLBACK(toggle_button_cb), toolbar); |
8427 | 1152 g_signal_connect(G_OBJECT(imhtml), "format_function_clear", G_CALLBACK(reset_buttons_cb), toolbar); |
8506 | 1153 g_signal_connect(G_OBJECT(imhtml), "format_function_update", G_CALLBACK(update_format_cb), toolbar); |
8516 | 1154 g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set", G_CALLBACK(mark_set_cb), toolbar); |
8481 | 1155 |
8788 | 1156 buttons = gtk_imhtml_get_format_functions(GTK_IMHTML(imhtml)); |
8807 | 1157 update_buttons_cb(GTK_IMHTML(imhtml), buttons, toolbar); |
8788 | 1158 |
8481 | 1159 bold = italic = underline = FALSE; |
1160 | |
8516 | 1161 gtk_imhtml_get_current_format(GTK_IMHTML(imhtml), &bold, &italic, &underline); |
10134 | 1162 |
8481 | 1163 if(bold) |
1164 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->bold), bold, | |
1165 toolbar); | |
10134 | 1166 |
8481 | 1167 if(italic) |
1168 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->italic), italic, | |
1169 toolbar); | |
1170 | |
1171 if(underline) | |
1172 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->underline), | |
1173 underline, toolbar); | |
8317 | 1174 } |
8427 | 1175 |
1176 void gtk_imhtmltoolbar_associate_smileys(GtkIMHtmlToolbar *toolbar, const char *proto_id) | |
1177 { | |
1178 if (toolbar->sml) | |
1179 g_free(toolbar->sml); | |
10134 | 1180 |
8427 | 1181 toolbar->sml = g_strdup(proto_id); |
1182 } |