Mercurial > pidgin
annotate src/gtkimhtmltoolbar.c @ 8728:268461757fd6
[gaim-migrate @ 9483]
forgot this
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Tue, 20 Apr 2004 20:28:55 +0000 |
parents | 2ac2f4cf1de5 |
children | 67f733c1cff8 |
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 | |
8677 | 361 gtk_imhtml_insert_link(GTK_IMHTML(toolbar->imhtml), |
362 gtk_text_buffer_get_insert(GTK_IMHTML(toolbar->imhtml)->text_buffer), | |
363 url, description); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
364 |
8317 | 365 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->link), FALSE); |
366 | |
367 toolbar->link_dialog = NULL; | |
368 } | |
369 | |
370 static void | |
371 insert_link_cb(GtkWidget *w, GtkIMHtmlToolbar *toolbar) | |
372 { | |
373 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->link))) { | |
374 GaimRequestFields *fields; | |
375 GaimRequestFieldGroup *group; | |
376 GaimRequestField *field; | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
377 |
8317 | 378 fields = gaim_request_fields_new(); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
379 |
8317 | 380 group = gaim_request_field_group_new(NULL); |
381 gaim_request_fields_add_group(fields, group); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
382 |
8317 | 383 field = gaim_request_field_string_new("url", _("_URL"), NULL, FALSE); |
384 gaim_request_field_set_required(field, TRUE); | |
385 gaim_request_field_group_add_field(group, field); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
386 |
8317 | 387 field = gaim_request_field_string_new("description", _("_Description"), |
388 NULL, FALSE); | |
389 gaim_request_field_group_add_field(group, field); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
390 |
8317 | 391 toolbar->link_dialog = |
392 gaim_request_fields(toolbar, _("Insert Link"), | |
393 NULL, | |
394 _("Please enter the URL and description of the " | |
395 "link that you want to insert. The description " | |
396 "is optional."), | |
397 fields, | |
398 _("_Insert"), G_CALLBACK(do_insert_link_cb), | |
399 _("Cancel"), G_CALLBACK(cancel_link_cb), | |
400 toolbar); | |
8322
ffb601c6b833
[gaim-migrate @ 9046]
Christian Hammond <chipx86@chipx86.com>
parents:
8321
diff
changeset
|
401 } else { |
8317 | 402 close_link_dialog(toolbar); |
403 } | |
404 gtk_widget_grab_focus(toolbar->imhtml); | |
405 } | |
406 | |
407 | |
408 static void | |
409 do_insert_image_cb(GtkWidget *widget, int resp, GtkIMHtmlToolbar *toolbar) | |
410 { | |
411 char *name, *filename; | |
412 char *buf, *filedata; | |
413 size_t size; | |
414 GError *error = NULL; | |
415 int id; | |
416 | |
417 if (resp != GTK_RESPONSE_OK) { | |
418 //set_toggle(toolbar->image, FALSE); | |
419 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->image), FALSE); | |
420 return; | |
421 } | |
422 | |
423 name = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(widget))); | |
424 | |
425 if (!name) { | |
426 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->image), FALSE); | |
427 return; | |
428 } | |
429 | |
430 if (gaim_gtk_check_if_dir(name, GTK_FILE_SELECTION(widget))) { | |
431 g_free(name); | |
432 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->image), FALSE); | |
433 return; | |
434 } | |
435 | |
436 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->image), FALSE); | |
437 | |
438 if (!g_file_get_contents(name, &filedata, &size, &error)) { | |
439 gaim_notify_error(NULL, NULL, error->message, NULL); | |
440 | |
441 g_error_free(error); | |
442 g_free(name); | |
443 | |
444 return; | |
445 } | |
446 | |
447 filename = name; | |
448 while (strchr(filename, '/')) | |
449 filename = strchr(filename, '/') + 1; | |
450 | |
451 id = gaim_imgstore_add(filedata, size, filename); | |
452 g_free(filedata); | |
453 | |
454 if (!id) { | |
455 buf = g_strdup_printf(_("Failed to store image: %s\n"), name); | |
456 gaim_notify_error(NULL, NULL, buf, NULL); | |
457 | |
458 g_free(buf); | |
459 g_free(name); | |
460 | |
461 return; | |
462 } | |
463 | |
464 //im->images = g_slist_append(im->images, GINT_TO_POINTER(id)); | |
465 | |
466 /*buf = g_strdup_printf("<IMG ID=\"%d\" SRC=\"file://%s\">", id, filename); | |
467 gtk_text_buffer_insert_at_cursor(GTK_TEXT_BUFFER(gtkconv->entry_buffer), buf, -1); | |
468 g_free(buf); | |
469 */ | |
470 g_free(name); | |
471 } | |
472 | |
473 | |
474 static void | |
475 insert_image_cb(GtkWidget *save, GtkIMHtmlToolbar *toolbar) | |
476 { | |
477 char buf[BUF_LONG]; | |
478 GtkWidget *window; | |
479 | |
480 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->image))) { | |
481 window = gtk_file_selection_new(_("Insert Image")); | |
482 g_snprintf(buf, sizeof(buf), "%s" G_DIR_SEPARATOR_S, gaim_home_dir()); | |
483 gtk_file_selection_set_filename(GTK_FILE_SELECTION(window), buf); | |
484 | |
485 gtk_dialog_set_default_response(GTK_DIALOG(window), GTK_RESPONSE_OK); | |
486 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(window)), | |
487 "response", G_CALLBACK(do_insert_image_cb), toolbar); | |
488 | |
489 gtk_widget_show(window); | |
490 toolbar->image_dialog = window; | |
491 } else { | |
492 gtk_widget_destroy(toolbar->image_dialog); | |
493 toolbar->image_dialog = NULL; | |
494 } | |
495 gtk_widget_grab_focus(toolbar->imhtml); | |
496 } | |
497 | |
498 | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
499 static void |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
500 close_smiley_dialog(GtkWidget *widget, GdkEvent *event, |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
501 GtkIMHtmlToolbar *toolbar) |
8317 | 502 { |
503 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
|
504 |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
505 if (toolbar->smiley_dialog != NULL) |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
506 { |
8317 | 507 gtk_widget_destroy(toolbar->smiley_dialog); |
508 toolbar->smiley_dialog = NULL; | |
509 } | |
510 } | |
511 | |
512 | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
513 static void |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
514 insert_smiley_text(GtkWidget *widget, GtkIMHtmlToolbar *toolbar) |
8317 | 515 { |
516 char *smiley_text = g_object_get_data(G_OBJECT(widget), "smiley_text"); | |
517 | |
8456 | 518 gtk_imhtml_insert_smiley(GTK_IMHTML(toolbar->imhtml), |
519 GTK_IMHTML(toolbar->imhtml)->protocol_name, | |
520 smiley_text); | |
8317 | 521 |
8320
5c6c8d48946f
[gaim-migrate @ 9044]
Christian Hammond <chipx86@chipx86.com>
parents:
8319
diff
changeset
|
522 close_smiley_dialog(NULL, NULL, toolbar); |
8317 | 523 } |
524 | |
525 | |
526 static void add_smiley(GtkIMHtmlToolbar *toolbar, GtkWidget *table, int row, int col, char *filename, char *face) | |
527 { | |
528 GtkWidget *image; | |
529 GtkWidget *button; | |
530 | |
531 image = gtk_image_new_from_file(filename); | |
532 button = gtk_button_new(); | |
533 gtk_container_add(GTK_CONTAINER(button), image); | |
534 g_object_set_data(G_OBJECT(button), "smiley_text", face); | |
535 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(insert_smiley_text), toolbar); | |
536 | |
537 gtk_tooltips_set_tip(toolbar->tooltips, button, face, NULL); | |
538 | |
539 gtk_table_attach_defaults(GTK_TABLE(table), button, col, col+1, row, row+1); | |
540 | |
541 /* these look really weird with borders */ | |
542 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
543 | |
544 gtk_widget_show(button); | |
545 } | |
546 | |
547 | |
548 static gboolean smiley_is_unique(GSList *list, GtkIMHtmlSmiley *smiley) { | |
549 while(list) { | |
550 GtkIMHtmlSmiley *cur = list->data; | |
551 if(!strcmp(cur->file, smiley->file)) | |
552 return FALSE; | |
553 list = list->next; | |
554 } | |
555 return TRUE; | |
556 } | |
557 | |
558 | |
559 static void | |
560 insert_smiley_cb(GtkWidget *smiley, GtkIMHtmlToolbar *toolbar) | |
561 { | |
562 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(smiley))) { | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
563 |
8317 | 564 GtkWidget *dialog; |
565 GtkWidget *smiley_table = NULL; | |
566 GSList *smileys, *unique_smileys = NULL; | |
567 int width; | |
568 int row = 0, col = 0; | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
569 |
8317 | 570 if (toolbar->smiley_dialog) { |
571 gtk_widget_grab_focus(toolbar->imhtml); | |
572 return; | |
573 } | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
574 |
8427 | 575 if (toolbar->sml) |
576 smileys = get_proto_smileys(toolbar->sml); | |
8317 | 577 else |
8427 | 578 smileys = get_proto_smileys(GAIM_PROTO_DEFAULT); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
579 |
8317 | 580 while(smileys) { |
581 GtkIMHtmlSmiley *smiley = smileys->data; | |
582 if(!smiley->hidden) { | |
583 if(smiley_is_unique(unique_smileys, smiley)) | |
584 unique_smileys = g_slist_append(unique_smileys, smiley); | |
585 } | |
586 smileys = smileys->next; | |
587 } | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
588 |
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
589 |
8317 | 590 width = floor(sqrt(g_slist_length(unique_smileys))); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
591 |
8317 | 592 GAIM_DIALOG(dialog); |
593 gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); | |
594 gtk_window_set_role(GTK_WINDOW(dialog), "smiley_dialog"); | |
595 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
|
596 |
8317 | 597 smiley_table = gtk_table_new(width, width, TRUE); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
598 |
8317 | 599 /* pack buttons */ |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
600 |
8317 | 601 while(unique_smileys) { |
602 GtkIMHtmlSmiley *smiley = unique_smileys->data; | |
603 if(!smiley->hidden) { | |
604 add_smiley(toolbar, smiley_table, row, col, smiley->file, smiley->smile); | |
605 if(++col >= width) { | |
606 col = 0; | |
607 row++; | |
608 } | |
609 } | |
610 unique_smileys = unique_smileys->next; | |
611 } | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
612 |
8317 | 613 gtk_container_add(GTK_CONTAINER(dialog), smiley_table); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
614 |
8317 | 615 gtk_widget_show(smiley_table); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
616 |
8317 | 617 gtk_container_set_border_width(GTK_CONTAINER(dialog), 5); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
618 |
8317 | 619 /* connect signals */ |
620 g_object_set_data(G_OBJECT(dialog), "dialog_type", "smiley dialog"); | |
621 g_signal_connect(G_OBJECT(dialog), "delete_event", | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
622 G_CALLBACK(close_smiley_dialog), toolbar); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
623 |
8317 | 624 /* show everything */ |
625 gtk_window_set_title(GTK_WINDOW(dialog), _("Smile!")); | |
626 gtk_widget_show_all(dialog); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
627 |
8317 | 628 toolbar->smiley_dialog = dialog; |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
629 |
8317 | 630 } else if (toolbar->smiley_dialog) { |
8320
5c6c8d48946f
[gaim-migrate @ 9044]
Christian Hammond <chipx86@chipx86.com>
parents:
8319
diff
changeset
|
631 close_smiley_dialog(smiley, NULL, toolbar); |
8317 | 632 } |
633 gtk_widget_grab_focus(toolbar->imhtml); | |
634 } | |
635 | |
8420 | 636 static void update_buttons_cb(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons, GtkIMHtmlToolbar *toolbar) |
637 { | |
638 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->bold), buttons & GTK_IMHTML_BOLD); | |
639 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->italic), buttons & GTK_IMHTML_ITALIC); | |
640 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->underline), buttons & GTK_IMHTML_UNDERLINE); | |
641 | |
642 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->larger_size), buttons & GTK_IMHTML_GROW); | |
643 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->smaller_size), buttons & GTK_IMHTML_SHRINK); | |
644 | |
645 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->font), buttons & GTK_IMHTML_FACE); | |
646 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->fgcolor), buttons & GTK_IMHTML_FORECOLOR); | |
647 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->bgcolor), buttons & GTK_IMHTML_BACKCOLOR); | |
648 | |
649 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->image), buttons & GTK_IMHTML_IMAGE); | |
650 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->link), buttons & GTK_IMHTML_LINK); | |
651 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->smiley), buttons & GTK_IMHTML_SMILEY); | |
8481 | 652 } |
8420 | 653 |
8481 | 654 /* we call this when we want to _set_active the toggle button, it'll |
655 * block the callback thats connected to the button so we don't have to | |
656 * do the double toggling hack | |
657 */ | |
658 static void toggle_button_set_active_block(GtkToggleButton *button, | |
659 gboolean is_active, | |
660 GtkIMHtmlToolbar *toolbar) | |
661 { | |
662 GObject *object; | |
663 g_return_if_fail(toolbar); | |
664 | |
665 object = g_object_ref(button); | |
666 g_signal_handlers_block_matched(object, G_SIGNAL_MATCH_DATA, | |
667 0, 0, NULL, NULL, toolbar); | |
668 gtk_toggle_button_set_active(button, is_active); | |
669 g_signal_handlers_unblock_matched(object, G_SIGNAL_MATCH_DATA, | |
670 0, 0, NULL, NULL, toolbar); | |
671 g_object_unref(object); | |
8420 | 672 } |
673 | |
674 static void toggle_button_cb(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons, GtkIMHtmlToolbar *toolbar) | |
675 { | |
8481 | 676 if (buttons & GTK_IMHTML_BOLD) |
677 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->bold), | |
678 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->bold)), | |
679 toolbar); | |
8420 | 680 |
8481 | 681 if (buttons & GTK_IMHTML_ITALIC) |
682 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->italic), | |
683 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->italic)), | |
684 toolbar); | |
8420 | 685 |
8481 | 686 if (buttons & GTK_IMHTML_UNDERLINE) |
687 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->underline), | |
688 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->underline)), | |
689 toolbar); | |
8420 | 690 } |
691 | |
8427 | 692 static void reset_buttons_cb(GtkIMHtml *imhtml, GtkIMHtmlToolbar *toolbar) |
693 { | |
8481 | 694 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->bold))) |
695 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->bold), FALSE, | |
696 toolbar); | |
697 | |
698 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->italic))) | |
699 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->italic), | |
700 FALSE, toolbar); | |
701 | |
702 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->underline))) | |
703 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->underline), | |
704 FALSE, toolbar); | |
705 } | |
8516 | 706 |
707 static void update_buttons(GtkIMHtmlToolbar *toolbar) { | |
8506 | 708 gboolean bold, italic, underline; |
709 | |
710 bold = italic = underline = FALSE; | |
8516 | 711 gtk_imhtml_get_current_format(GTK_IMHTML(toolbar->imhtml), |
712 &bold, &italic, &underline); | |
8506 | 713 |
714 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->bold)) != bold) | |
715 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->bold), bold, | |
716 toolbar); | |
8516 | 717 |
8506 | 718 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->italic)) != italic) |
719 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->italic), italic, | |
720 toolbar); | |
8516 | 721 |
8506 | 722 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->underline)) != underline) |
723 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->underline), | |
8677 | 724 underline, toolbar); |
8506 | 725 } |
8481 | 726 |
8516 | 727 static void update_format_cb(GtkIMHtml *imhtml, GtkIMHtmlToolbar *toolbar) { |
728 update_buttons(toolbar); | |
729 } | |
8481 | 730 |
8516 | 731 static void mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *location, |
732 GtkTextMark *mark, GtkIMHtmlToolbar *toolbar) | |
733 { | |
734 if(mark != gtk_text_buffer_get_insert(buffer)) | |
735 return; | |
736 | |
737 update_buttons(toolbar); | |
8427 | 738 } |
739 | |
8317 | 740 enum { |
741 LAST_SIGNAL | |
742 }; | |
743 //static guint signals [LAST_SIGNAL] = { 0 }; | |
744 | |
745 static void | |
746 gtk_imhtmltoolbar_finalize (GObject *object) | |
747 { | |
8391 | 748 GtkIMHtmlToolbar *toolbar = GTK_IMHTMLTOOLBAR(object); |
8317 | 749 |
8447 | 750 if (toolbar->smiley_dialog != NULL) |
751 { | |
752 gtk_widget_destroy(toolbar->smiley_dialog); | |
753 toolbar->smiley_dialog = NULL; | |
754 } | |
755 | |
8685
2ac2f4cf1de5
[gaim-migrate @ 9438]
Christian Hammond <chipx86@chipx86.com>
parents:
8677
diff
changeset
|
756 if (toolbar->link_dialog != NULL) |
2ac2f4cf1de5
[gaim-migrate @ 9438]
Christian Hammond <chipx86@chipx86.com>
parents:
8677
diff
changeset
|
757 { |
2ac2f4cf1de5
[gaim-migrate @ 9438]
Christian Hammond <chipx86@chipx86.com>
parents:
8677
diff
changeset
|
758 gaim_request_close(GAIM_REQUEST_FIELDS, toolbar->link_dialog); |
2ac2f4cf1de5
[gaim-migrate @ 9438]
Christian Hammond <chipx86@chipx86.com>
parents:
8677
diff
changeset
|
759 toolbar->link_dialog = NULL; |
2ac2f4cf1de5
[gaim-migrate @ 9438]
Christian Hammond <chipx86@chipx86.com>
parents:
8677
diff
changeset
|
760 } |
2ac2f4cf1de5
[gaim-migrate @ 9438]
Christian Hammond <chipx86@chipx86.com>
parents:
8677
diff
changeset
|
761 |
2ac2f4cf1de5
[gaim-migrate @ 9438]
Christian Hammond <chipx86@chipx86.com>
parents:
8677
diff
changeset
|
762 if (toolbar->image_dialog != NULL) |
2ac2f4cf1de5
[gaim-migrate @ 9438]
Christian Hammond <chipx86@chipx86.com>
parents:
8677
diff
changeset
|
763 { |
2ac2f4cf1de5
[gaim-migrate @ 9438]
Christian Hammond <chipx86@chipx86.com>
parents:
8677
diff
changeset
|
764 gtk_widget_destroy(toolbar->image_dialog); |
2ac2f4cf1de5
[gaim-migrate @ 9438]
Christian Hammond <chipx86@chipx86.com>
parents:
8677
diff
changeset
|
765 toolbar->image_dialog = NULL; |
2ac2f4cf1de5
[gaim-migrate @ 9438]
Christian Hammond <chipx86@chipx86.com>
parents:
8677
diff
changeset
|
766 } |
2ac2f4cf1de5
[gaim-migrate @ 9438]
Christian Hammond <chipx86@chipx86.com>
parents:
8677
diff
changeset
|
767 |
8427 | 768 if (toolbar->sml) |
769 free(toolbar->sml); | |
8391 | 770 gtk_object_sink(GTK_OBJECT(toolbar->tooltips)); |
8317 | 771 |
8391 | 772 G_OBJECT_CLASS(parent_class)->finalize (object); |
8317 | 773 } |
774 | |
775 /* Boring GTK stuff */ | |
776 static void gtk_imhtmltoolbar_class_init (GtkIMHtmlToolbarClass *class) | |
777 { | |
778 GtkObjectClass *object_class; | |
779 GObjectClass *gobject_class; | |
780 object_class = (GtkObjectClass*) class; | |
781 gobject_class = (GObjectClass*) class; | |
782 parent_class = gtk_type_class(GTK_TYPE_VBOX); | |
783 /* signals[URL_CLICKED] = g_signal_new(url_clicked", | |
784 G_TYPE_FROM_CLASS(gobject_class), | |
785 G_SIGNAL_RUN_FIRST, | |
786 G_STRUCT_OFFSET(GtkIMHtmlClass, url_clicked), | |
787 NULL, | |
788 0, | |
789 g_cclosure_marshal_VOID__POINTER, | |
790 G_TYPE_NONE, 1, | |
791 G_TYPE_POINTER);*/ | |
792 gobject_class->finalize = gtk_imhtmltoolbar_finalize; | |
793 } | |
794 | |
795 static void gtk_imhtmltoolbar_init (GtkIMHtmlToolbar *toolbar) | |
796 { | |
797 GtkWidget *hbox; | |
798 GtkWidget *button; | |
799 GtkWidget *sep; | |
800 GtkSizeGroup *sg; | |
801 | |
802 toolbar->imhtml = NULL; | |
803 toolbar->font_dialog = NULL; | |
804 toolbar->fgcolor_dialog = NULL; | |
805 toolbar->bgcolor_dialog = NULL; | |
806 toolbar->link_dialog = NULL; | |
807 toolbar->smiley_dialog = NULL; | |
808 toolbar->image_dialog = NULL; | |
809 | |
810 toolbar->tooltips = gtk_tooltips_new(); | |
811 | |
812 sg = gtk_size_group_new(GTK_SIZE_GROUP_BOTH); | |
813 | |
814 sep = gtk_hseparator_new(); | |
815 gtk_box_pack_start(GTK_BOX(toolbar), sep, FALSE, FALSE, 0); | |
816 gtk_widget_show(sep); | |
817 | |
818 hbox = gtk_hbox_new(FALSE, 6); | |
819 gtk_box_pack_start(GTK_BOX(toolbar), hbox, FALSE, FALSE, 0); | |
820 | |
821 /* Bold */ | |
822 button = gaim_pixbuf_toolbar_button_from_stock(GTK_STOCK_BOLD); | |
823 gtk_size_group_add_widget(sg, button); | |
824 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
825 gtk_tooltips_set_tip(toolbar->tooltips, button, _("Bold"), NULL); | |
826 | |
827 g_signal_connect(G_OBJECT(button), "clicked", | |
828 G_CALLBACK(do_bold), toolbar); | |
829 | |
830 toolbar->bold = button; | |
831 | |
832 /* Italic */ | |
833 button = gaim_pixbuf_toolbar_button_from_stock(GTK_STOCK_ITALIC); | |
834 gtk_size_group_add_widget(sg, button); | |
835 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
836 gtk_tooltips_set_tip(toolbar->tooltips, button, _("Italic"), NULL); | |
837 | |
838 g_signal_connect(G_OBJECT(button), "clicked", | |
839 G_CALLBACK(do_italic), toolbar); | |
840 | |
841 toolbar->italic = button; | |
842 | |
843 /* Underline */ | |
844 button = gaim_pixbuf_toolbar_button_from_stock(GTK_STOCK_UNDERLINE); | |
845 gtk_size_group_add_widget(sg, button); | |
846 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
847 gtk_tooltips_set_tip(toolbar->tooltips, button, _("Underline"), NULL); | |
848 | |
849 g_signal_connect(G_OBJECT(button), "clicked", | |
850 G_CALLBACK(do_underline), toolbar); | |
851 | |
852 toolbar->underline = button; | |
853 | |
854 /* Sep */ | |
855 sep = gtk_vseparator_new(); | |
856 gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0); | |
857 | |
858 /* Increase font size */ | |
859 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_TEXT_BIGGER); | |
860 gtk_size_group_add_widget(sg, button); | |
861 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
862 gtk_tooltips_set_tip(toolbar->tooltips, button, | |
863 _("Larger font size"), NULL); | |
864 | |
865 g_signal_connect(G_OBJECT(button), "clicked", | |
866 G_CALLBACK(do_big), toolbar); | |
867 | |
868 toolbar->larger_size = button; | |
869 | |
870 /* Decrease font size */ | |
871 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_TEXT_SMALLER); | |
872 gtk_size_group_add_widget(sg, button); | |
873 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
874 gtk_tooltips_set_tip(toolbar->tooltips, button, | |
875 _("Smaller font size"), NULL); | |
876 | |
877 g_signal_connect(G_OBJECT(button), "clicked", | |
878 G_CALLBACK(do_small), toolbar); | |
879 | |
880 toolbar->smaller_size = button; | |
881 | |
882 /* Sep */ | |
883 sep = gtk_vseparator_new(); | |
884 gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0); | |
885 | |
886 /* Font Face */ | |
887 | |
888 button = gaim_pixbuf_toolbar_button_from_stock(GTK_STOCK_SELECT_FONT); | |
889 gtk_size_group_add_widget(sg, button); | |
890 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
891 gtk_tooltips_set_tip(toolbar->tooltips, button, | |
892 _("Font Face"), NULL); | |
893 | |
894 g_signal_connect(G_OBJECT(button), "clicked", | |
895 G_CALLBACK(toggle_font), toolbar); | |
896 | |
897 toolbar->font = button; | |
898 | |
899 /* Foreground Color */ | |
900 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_FGCOLOR); | |
901 gtk_size_group_add_widget(sg, button); | |
902 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
903 gtk_tooltips_set_tip(toolbar->tooltips, button, | |
904 _("Foreground font color"), NULL); | |
905 | |
906 g_signal_connect(G_OBJECT(button), "clicked", | |
907 G_CALLBACK(toggle_fg_color), toolbar); | |
908 | |
909 toolbar->fgcolor = button; | |
910 | |
911 /* Background Color */ | |
912 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_BGCOLOR); | |
913 gtk_size_group_add_widget(sg, button); | |
914 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
915 gtk_tooltips_set_tip(toolbar->tooltips, button, | |
916 _("Background color"), NULL); | |
917 | |
918 g_signal_connect(G_OBJECT(button), "clicked", | |
919 G_CALLBACK(toggle_bg_color), toolbar); | |
920 | |
921 toolbar->bgcolor = button; | |
922 | |
923 /* Sep */ | |
924 sep = gtk_vseparator_new(); | |
925 gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0); | |
926 | |
927 /* Insert Link */ | |
928 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_LINK); | |
929 gtk_size_group_add_widget(sg, button); | |
930 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
931 gtk_tooltips_set_tip(toolbar->tooltips, button, _("Insert link"), NULL); | |
932 g_signal_connect(G_OBJECT(button), "clicked", | |
933 G_CALLBACK(insert_link_cb), toolbar); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
934 |
8317 | 935 toolbar->link = button; |
936 | |
937 /* Insert IM Image */ | |
938 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_IMAGE); | |
939 gtk_size_group_add_widget(sg, button); | |
940 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
941 gtk_tooltips_set_tip(toolbar->tooltips, button, _("Insert image"), NULL); | |
942 | |
943 g_signal_connect(G_OBJECT(button), "clicked", | |
944 G_CALLBACK(insert_image_cb), toolbar); | |
945 | |
946 toolbar->image = button; | |
947 | |
948 /* Insert Smiley */ | |
949 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_SMILEY); | |
950 gtk_size_group_add_widget(sg, button); | |
951 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
952 gtk_tooltips_set_tip(toolbar->tooltips, button, _("Insert smiley"), NULL); | |
953 | |
954 g_signal_connect(G_OBJECT(button), "clicked", | |
955 G_CALLBACK(insert_smiley_cb), toolbar); | |
956 | |
957 toolbar->smiley = button; | |
958 | |
959 | |
960 sep = gtk_hseparator_new(); | |
961 gtk_box_pack_start(GTK_BOX(toolbar), sep, FALSE, FALSE, 0); | |
962 gtk_widget_show(sep); | |
8427 | 963 toolbar->sml = NULL; |
8317 | 964 gtk_widget_show_all(hbox); |
965 } | |
966 | |
967 GtkWidget *gtk_imhtmltoolbar_new() | |
968 { | |
969 return GTK_WIDGET(g_object_new(gtk_imhtmltoolbar_get_type(), NULL)); | |
970 } | |
971 | |
972 GType gtk_imhtmltoolbar_get_type() | |
973 { | |
974 static GType imhtmltoolbar_type = 0; | |
975 | |
976 if (!imhtmltoolbar_type) { | |
977 static const GTypeInfo imhtmltoolbar_info = { | |
978 sizeof(GtkIMHtmlToolbarClass), | |
979 NULL, | |
980 NULL, | |
981 (GClassInitFunc) gtk_imhtmltoolbar_class_init, | |
982 NULL, | |
983 NULL, | |
984 sizeof (GtkIMHtmlToolbar), | |
985 0, | |
986 (GInstanceInitFunc) gtk_imhtmltoolbar_init | |
987 }; | |
988 | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
989 imhtmltoolbar_type = g_type_register_static(GTK_TYPE_VBOX, |
8317 | 990 "GtkIMHtmlToolbar", &imhtmltoolbar_info, 0); |
991 } | |
992 | |
993 return imhtmltoolbar_type; | |
994 } | |
995 | |
996 | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
997 void gtk_imhtmltoolbar_attach(GtkIMHtmlToolbar *toolbar, GtkWidget *imhtml) |
8317 | 998 { |
8481 | 999 gboolean bold, italic, underline; |
1000 | |
8325
415283e39bce
[gaim-migrate @ 9049]
Christian Hammond <chipx86@chipx86.com>
parents:
8324
diff
changeset
|
1001 g_return_if_fail(toolbar != NULL); |
415283e39bce
[gaim-migrate @ 9049]
Christian Hammond <chipx86@chipx86.com>
parents:
8324
diff
changeset
|
1002 g_return_if_fail(GTK_IS_IMHTMLTOOLBAR(toolbar)); |
415283e39bce
[gaim-migrate @ 9049]
Christian Hammond <chipx86@chipx86.com>
parents:
8324
diff
changeset
|
1003 g_return_if_fail(imhtml != NULL); |
415283e39bce
[gaim-migrate @ 9049]
Christian Hammond <chipx86@chipx86.com>
parents:
8324
diff
changeset
|
1004 g_return_if_fail(GTK_IS_IMHTML(imhtml)); |
415283e39bce
[gaim-migrate @ 9049]
Christian Hammond <chipx86@chipx86.com>
parents:
8324
diff
changeset
|
1005 |
8317 | 1006 toolbar->imhtml = imhtml; |
8506 | 1007 g_signal_connect(G_OBJECT(imhtml), "format_buttons_update", G_CALLBACK(update_buttons_cb), toolbar); |
8420 | 1008 g_signal_connect(G_OBJECT(imhtml), "format_function_toggle", G_CALLBACK(toggle_button_cb), toolbar); |
8427 | 1009 g_signal_connect(G_OBJECT(imhtml), "format_function_clear", G_CALLBACK(reset_buttons_cb), toolbar); |
8506 | 1010 g_signal_connect(G_OBJECT(imhtml), "format_function_update", G_CALLBACK(update_format_cb), toolbar); |
8516 | 1011 g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set", G_CALLBACK(mark_set_cb), toolbar); |
8481 | 1012 |
1013 bold = italic = underline = FALSE; | |
1014 | |
8516 | 1015 gtk_imhtml_get_current_format(GTK_IMHTML(imhtml), &bold, &italic, &underline); |
8481 | 1016 |
1017 if(bold) | |
1018 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->bold), bold, | |
1019 toolbar); | |
1020 | |
1021 if(italic) | |
1022 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->italic), italic, | |
1023 toolbar); | |
1024 | |
1025 if(underline) | |
1026 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar->underline), | |
1027 underline, toolbar); | |
8317 | 1028 } |
8427 | 1029 |
1030 void gtk_imhtmltoolbar_associate_smileys(GtkIMHtmlToolbar *toolbar, const char *proto_id) | |
1031 { | |
1032 if (toolbar->sml) | |
1033 g_free(toolbar->sml); | |
1034 | |
1035 toolbar->sml = g_strdup(proto_id); | |
1036 } |