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