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