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