Mercurial > pidgin.yaz
annotate src/gtkimhtmltoolbar.c @ 8466:5562e8a74c94
[gaim-migrate @ 9196]
" if the user has the pref set to false, we're still
handling the key.. This is bad if for instance.. the
user wants to do something like ctrl-shift-b-3 to
display a superscripted 3. This patch makes the
callback function return FALSE so that it will
propergate down to the GtkTextView and give the user
the desired behavior.
i realized this will conflict when i finish 9, 10, and 11 on
simguys list, and since i already had 11 done.. I'll just
throw it in with this.. so here's the updated update patch ;)
simguy's imhtml bug 11 is that the italic and underline
buttons don't get toggled when you press ctrl-i ctrl-u this
fixes that as well as my initial comment ;)" --Gary Kramlich
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Wed, 17 Mar 2004 20:23:44 +0000 |
parents | 5f8d4ab6d375 |
children | 6d0869404696 |
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 { | |
39 g_return_if_fail(toolbar); | |
40 gtk_imhtml_toggle_bold(GTK_IMHTML(toolbar->imhtml)); | |
41 gtk_widget_grab_focus(toolbar->imhtml); | |
42 } | |
43 | |
44 static void | |
45 do_italic(GtkWidget *italic, GtkIMHtmlToolbar *toolbar) | |
46 { | |
47 g_return_if_fail(toolbar); | |
48 gtk_imhtml_toggle_italic(GTK_IMHTML(toolbar->imhtml)); | |
49 gtk_widget_grab_focus(toolbar->imhtml); | |
50 } | |
51 | |
52 static void | |
53 do_underline(GtkWidget *underline, GtkIMHtmlToolbar *toolbar) | |
54 { | |
55 g_return_if_fail(toolbar); | |
56 gtk_imhtml_toggle_underline(GTK_IMHTML(toolbar->imhtml)); | |
57 gtk_widget_grab_focus(toolbar->imhtml); | |
58 } | |
59 | |
60 static void | |
61 do_small(GtkWidget *smalltb, GtkIMHtmlToolbar *toolbar) | |
62 { | |
63 g_return_if_fail(toolbar); | |
8380 | 64 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->smaller_size))) |
65 gtk_imhtml_font_shrink(GTK_IMHTML(toolbar->imhtml)); | |
8317 | 66 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->smaller_size), FALSE); |
67 gtk_widget_grab_focus(toolbar->imhtml); | |
68 } | |
69 | |
70 static void | |
71 do_big(GtkWidget *large, GtkIMHtmlToolbar *toolbar) | |
72 { | |
73 g_return_if_fail(toolbar); | |
8380 | 74 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->larger_size))) |
75 gtk_imhtml_font_grow(GTK_IMHTML(toolbar->imhtml)); | |
8317 | 76 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->larger_size), FALSE); |
77 gtk_widget_grab_focus(toolbar->imhtml); | |
78 } | |
79 | |
80 | |
81 | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
82 static void |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
83 destroy_toolbar_font(GtkWidget *widget, GdkEvent *event, |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
84 GtkIMHtmlToolbar *toolbar) |
8317 | 85 { |
86 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->font), FALSE); | |
87 | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
88 if (toolbar->font_dialog != NULL) |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
89 { |
8317 | 90 gtk_widget_destroy(toolbar->font_dialog); |
91 toolbar->font_dialog = NULL; | |
92 } | |
93 } | |
94 | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
95 static void |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
96 cancel_toolbar_font(GtkWidget *widget, GtkIMHtmlToolbar *toolbar) |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
97 { |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
98 destroy_toolbar_font(widget, NULL, toolbar); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
99 } |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
100 |
8317 | 101 static void apply_font(GtkWidget *widget, GtkFontSelection *fontsel) |
102 { | |
103 /* this could be expanded to include font size, weight, etc. | |
104 but for now only works with font face */ | |
105 char *fontname; | |
106 char *space; | |
107 GtkIMHtmlToolbar *toolbar = g_object_get_data(G_OBJECT(fontsel), "gaim_toolbar"); | |
108 | |
109 fontname = gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(fontsel)); | |
110 | |
111 space = strrchr(fontname, ' '); | |
112 if(space && isdigit(*(space+1))) | |
113 *space = '\0'; | |
114 | |
115 gtk_imhtml_toggle_fontface(GTK_IMHTML(toolbar->imhtml), fontname); | |
116 | |
117 g_free(fontname); | |
118 | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
119 cancel_toolbar_font(NULL, toolbar); |
8317 | 120 } |
121 | |
122 static void | |
123 toggle_font(GtkWidget *font, GtkIMHtmlToolbar *toolbar) | |
124 { | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
125 #if 0 |
8317 | 126 char fonttif[128]; |
127 const char *fontface; | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
128 #endif |
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
129 |
8317 | 130 g_return_if_fail(toolbar); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
131 |
8317 | 132 if (!toolbar->font_dialog) { |
133 toolbar->font_dialog = gtk_font_selection_dialog_new(_("Select Font")); | |
134 | |
135 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
|
136 |
8317 | 137 /* if (gtkconv->fontface[0]) { |
138 g_snprintf(fonttif, sizeof(fonttif), "%s 12", gtkconv->fontface); | |
139 gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(gtkconv->dialogs.font), | |
140 fonttif); | |
141 } else { | |
142 gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(gtkconv->dialogs.font), | |
143 DEFAULT_FONT_FACE); | |
144 } | |
145 */ | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
146 |
8317 | 147 g_signal_connect(G_OBJECT(toolbar->font_dialog), "delete_event", |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
148 G_CALLBACK(destroy_toolbar_font), toolbar); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
149 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
|
150 G_CALLBACK(apply_font), toolbar->font_dialog); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
151 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
|
152 G_CALLBACK(cancel_toolbar_font), toolbar); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
153 |
8317 | 154 gtk_window_present(GTK_WINDOW(toolbar->font_dialog)); |
155 } else { | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
156 cancel_toolbar_font(NULL, toolbar); |
8317 | 157 } |
158 gtk_widget_grab_focus(toolbar->imhtml); | |
159 } | |
160 | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
161 static void |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
162 destroy_toolbar_fgcolor(GtkWidget *widget, GdkEvent *event, |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
163 GtkIMHtmlToolbar *toolbar) |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
164 { |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
165 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->fgcolor), FALSE); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
166 |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
167 if (toolbar->fgcolor_dialog != NULL) |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
168 { |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
169 gtk_widget_destroy(toolbar->fgcolor_dialog); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
170 toolbar->fgcolor_dialog = NULL; |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
171 } |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
172 } |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
173 |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
174 static void cancel_toolbar_fgcolor(GtkWidget *widget, |
8321
eb269b81fff8
[gaim-migrate @ 9045]
Christian Hammond <chipx86@chipx86.com>
parents:
8320
diff
changeset
|
175 GtkIMHtmlToolbar *toolbar) |
8317 | 176 { |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
177 destroy_toolbar_fgcolor(widget, NULL, toolbar); |
8317 | 178 } |
179 | |
180 static void do_fgcolor(GtkWidget *widget, GtkColorSelection *colorsel) | |
181 { | |
182 GdkColor text_color; | |
183 GtkIMHtmlToolbar *toolbar = g_object_get_data(G_OBJECT(colorsel), "gaim_toolbar"); | |
184 char *open_tag; | |
185 | |
186 open_tag = g_malloc(30); | |
187 gtk_color_selection_get_current_color(colorsel, &text_color); | |
188 g_snprintf(open_tag, 23, "#%02X%02X%02X", | |
189 text_color.red / 256, | |
190 text_color.green / 256, | |
191 text_color.blue / 256); | |
192 gtk_imhtml_toggle_forecolor(GTK_IMHTML(toolbar->imhtml), open_tag); | |
193 | |
194 g_free(open_tag); | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
195 cancel_toolbar_fgcolor(NULL, toolbar); |
8317 | 196 } |
197 | |
198 static void | |
199 toggle_fg_color(GtkWidget *color, GtkIMHtmlToolbar *toolbar) | |
200 { | |
201 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(color))) { | |
202 GtkWidget *colorsel; | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
203 /* GdkColor fgcolor; */ |
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
204 |
8317 | 205 /*gdk_color_parse(gaim_prefs_get_string("/gaim/gtk/conversations/fgcolor"), |
206 &fgcolor);*/ | |
207 if (!toolbar->fgcolor_dialog) { | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
208 |
8317 | 209 toolbar->fgcolor_dialog = gtk_color_selection_dialog_new(_("Select Text Color")); |
210 colorsel = GTK_COLOR_SELECTION_DIALOG(toolbar->fgcolor_dialog)->colorsel; | |
211 //gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel), &fgcolor); | |
212 g_object_set_data(G_OBJECT(colorsel), "gaim_toolbar", toolbar); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
213 |
8317 | 214 g_signal_connect(G_OBJECT(toolbar->fgcolor_dialog), "delete_event", |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
215 G_CALLBACK(destroy_toolbar_fgcolor), toolbar); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
216 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
|
217 G_CALLBACK(do_fgcolor), colorsel); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
218 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
|
219 G_CALLBACK(cancel_toolbar_fgcolor), toolbar); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
220 |
8317 | 221 } |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
222 gtk_window_present(GTK_WINDOW(toolbar->fgcolor_dialog)); |
8317 | 223 } else if (toolbar->fgcolor_dialog != NULL) { |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
224 cancel_toolbar_fgcolor(color, toolbar); |
8317 | 225 } else { |
226 //gaim_gtk_advance_past(gtkconv, "<FONT COLOR>", "</FONT>"); | |
227 } | |
228 gtk_widget_grab_focus(toolbar->imhtml); | |
229 } | |
230 | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
231 static void |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
232 destroy_toolbar_bgcolor(GtkWidget *widget, GdkEvent *event, |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
233 GtkIMHtmlToolbar *toolbar) |
8317 | 234 { |
235 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
|
236 |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
237 if (toolbar->bgcolor_dialog != NULL) |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
238 { |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
239 gtk_widget_destroy(toolbar->bgcolor_dialog); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
240 toolbar->bgcolor_dialog = NULL; |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
241 } |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
242 } |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
243 |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
244 static void |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
245 cancel_toolbar_bgcolor(GtkWidget *widget, GtkIMHtmlToolbar *toolbar) |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
246 { |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
247 destroy_toolbar_bgcolor(widget, NULL, toolbar); |
8317 | 248 } |
249 | |
250 static void do_bgcolor(GtkWidget *widget, GtkColorSelection *colorsel) | |
251 { | |
252 GdkColor text_color; | |
253 GtkIMHtmlToolbar *toolbar = g_object_get_data(G_OBJECT(colorsel), "gaim_toolbar"); | |
254 char *open_tag; | |
255 | |
256 open_tag = g_malloc(30); | |
257 gtk_color_selection_get_current_color(colorsel, &text_color); | |
258 g_snprintf(open_tag, 23, "#%02X%02X%02X", | |
259 text_color.red / 256, | |
260 text_color.green / 256, | |
261 text_color.blue / 256); | |
262 gtk_imhtml_toggle_backcolor(GTK_IMHTML(toolbar->imhtml), open_tag); | |
263 | |
264 g_free(open_tag); | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
265 cancel_toolbar_bgcolor(NULL, toolbar); |
8317 | 266 } |
267 | |
268 static void | |
269 toggle_bg_color(GtkWidget *color, GtkIMHtmlToolbar *toolbar) | |
270 { | |
271 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(color))) { | |
272 GtkWidget *colorsel; | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
273 /* GdkColor bgcolor; */ |
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
274 |
8317 | 275 /*gdk_color_parse(gaim_prefs_get_string("/gaim/gtk/conversations/bgcolor"), |
276 &bgcolor);*/ | |
277 if (!toolbar->bgcolor_dialog) { | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
278 |
8359 | 279 toolbar->bgcolor_dialog = gtk_color_selection_dialog_new(_("Select Background Color")); |
8317 | 280 colorsel = GTK_COLOR_SELECTION_DIALOG(toolbar->bgcolor_dialog)->colorsel; |
281 //gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel), &bgcolor); | |
282 g_object_set_data(G_OBJECT(colorsel), "gaim_toolbar", toolbar); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
283 |
8317 | 284 g_signal_connect(G_OBJECT(toolbar->bgcolor_dialog), "delete_event", |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
285 G_CALLBACK(destroy_toolbar_bgcolor), toolbar); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
286 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
|
287 G_CALLBACK(do_bgcolor), colorsel); |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
288 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
|
289 G_CALLBACK(cancel_toolbar_bgcolor), toolbar); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
290 |
8317 | 291 } |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
292 gtk_window_present(GTK_WINDOW(toolbar->bgcolor_dialog)); |
8317 | 293 } else if (toolbar->bgcolor_dialog != NULL) { |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
294 cancel_toolbar_bgcolor(color, toolbar); |
8317 | 295 } else { |
296 //gaim_gtk_advance_past(gtkconv, "<FONT COLOR>", "</FONT>"); | |
297 } | |
298 gtk_widget_grab_focus(toolbar->imhtml); | |
299 } | |
300 | |
301 static void | |
302 cancel_link_cb(GtkIMHtmlToolbar *toolbar, GaimRequestFields *fields) | |
303 { | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
304 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
|
305 |
8317 | 306 toolbar->link_dialog = NULL; |
307 } | |
308 | |
309 static void | |
310 close_link_dialog(GtkIMHtmlToolbar *toolbar) | |
311 { | |
312 if (toolbar->link_dialog != NULL) | |
313 { | |
314 gaim_request_close(GAIM_REQUEST_FIELDS, toolbar->link_dialog); | |
315 toolbar->link_dialog = NULL; | |
316 } | |
317 } | |
318 | |
319 static void | |
320 do_insert_link_cb(GtkIMHtmlToolbar *toolbar, GaimRequestFields *fields) | |
321 { | |
322 const char *url, *description; | |
323 | |
324 url = gaim_request_fields_get_string(fields, "url"); | |
325 description = gaim_request_fields_get_string(fields, "description"); | |
326 | |
327 if (description == NULL) | |
328 description = url; | |
329 | |
330 gtk_imhtml_insert_link(GTK_IMHTML(toolbar->imhtml), url, description); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
331 |
8317 | 332 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->link), FALSE); |
333 | |
334 toolbar->link_dialog = NULL; | |
335 } | |
336 | |
337 static void | |
338 insert_link_cb(GtkWidget *w, GtkIMHtmlToolbar *toolbar) | |
339 { | |
340 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->link))) { | |
341 GaimRequestFields *fields; | |
342 GaimRequestFieldGroup *group; | |
343 GaimRequestField *field; | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
344 |
8317 | 345 fields = gaim_request_fields_new(); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
346 |
8317 | 347 group = gaim_request_field_group_new(NULL); |
348 gaim_request_fields_add_group(fields, group); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
349 |
8317 | 350 field = gaim_request_field_string_new("url", _("_URL"), NULL, FALSE); |
351 gaim_request_field_set_required(field, TRUE); | |
352 gaim_request_field_group_add_field(group, field); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
353 |
8317 | 354 field = gaim_request_field_string_new("description", _("_Description"), |
355 NULL, FALSE); | |
356 gaim_request_field_group_add_field(group, field); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
357 |
8317 | 358 toolbar->link_dialog = |
359 gaim_request_fields(toolbar, _("Insert Link"), | |
360 NULL, | |
361 _("Please enter the URL and description of the " | |
362 "link that you want to insert. The description " | |
363 "is optional."), | |
364 fields, | |
365 _("_Insert"), G_CALLBACK(do_insert_link_cb), | |
366 _("Cancel"), G_CALLBACK(cancel_link_cb), | |
367 toolbar); | |
8322
ffb601c6b833
[gaim-migrate @ 9046]
Christian Hammond <chipx86@chipx86.com>
parents:
8321
diff
changeset
|
368 } else { |
8317 | 369 close_link_dialog(toolbar); |
370 } | |
371 gtk_widget_grab_focus(toolbar->imhtml); | |
372 } | |
373 | |
374 | |
375 static void | |
376 do_insert_image_cb(GtkWidget *widget, int resp, GtkIMHtmlToolbar *toolbar) | |
377 { | |
378 char *name, *filename; | |
379 char *buf, *filedata; | |
380 size_t size; | |
381 GError *error = NULL; | |
382 int id; | |
383 | |
384 if (resp != GTK_RESPONSE_OK) { | |
385 //set_toggle(toolbar->image, FALSE); | |
386 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->image), FALSE); | |
387 return; | |
388 } | |
389 | |
390 name = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(widget))); | |
391 | |
392 if (!name) { | |
393 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->image), FALSE); | |
394 return; | |
395 } | |
396 | |
397 if (gaim_gtk_check_if_dir(name, GTK_FILE_SELECTION(widget))) { | |
398 g_free(name); | |
399 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->image), FALSE); | |
400 return; | |
401 } | |
402 | |
403 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->image), FALSE); | |
404 | |
405 if (!g_file_get_contents(name, &filedata, &size, &error)) { | |
406 gaim_notify_error(NULL, NULL, error->message, NULL); | |
407 | |
408 g_error_free(error); | |
409 g_free(name); | |
410 | |
411 return; | |
412 } | |
413 | |
414 filename = name; | |
415 while (strchr(filename, '/')) | |
416 filename = strchr(filename, '/') + 1; | |
417 | |
418 id = gaim_imgstore_add(filedata, size, filename); | |
419 g_free(filedata); | |
420 | |
421 if (!id) { | |
422 buf = g_strdup_printf(_("Failed to store image: %s\n"), name); | |
423 gaim_notify_error(NULL, NULL, buf, NULL); | |
424 | |
425 g_free(buf); | |
426 g_free(name); | |
427 | |
428 return; | |
429 } | |
430 | |
431 //im->images = g_slist_append(im->images, GINT_TO_POINTER(id)); | |
432 | |
433 /*buf = g_strdup_printf("<IMG ID=\"%d\" SRC=\"file://%s\">", id, filename); | |
434 gtk_text_buffer_insert_at_cursor(GTK_TEXT_BUFFER(gtkconv->entry_buffer), buf, -1); | |
435 g_free(buf); | |
436 */ | |
437 g_free(name); | |
438 } | |
439 | |
440 | |
441 static void | |
442 insert_image_cb(GtkWidget *save, GtkIMHtmlToolbar *toolbar) | |
443 { | |
444 char buf[BUF_LONG]; | |
445 GtkWidget *window; | |
446 | |
447 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->image))) { | |
448 window = gtk_file_selection_new(_("Insert Image")); | |
449 g_snprintf(buf, sizeof(buf), "%s" G_DIR_SEPARATOR_S, gaim_home_dir()); | |
450 gtk_file_selection_set_filename(GTK_FILE_SELECTION(window), buf); | |
451 | |
452 gtk_dialog_set_default_response(GTK_DIALOG(window), GTK_RESPONSE_OK); | |
453 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(window)), | |
454 "response", G_CALLBACK(do_insert_image_cb), toolbar); | |
455 | |
456 gtk_widget_show(window); | |
457 toolbar->image_dialog = window; | |
458 } else { | |
459 gtk_widget_destroy(toolbar->image_dialog); | |
460 toolbar->image_dialog = NULL; | |
461 } | |
462 gtk_widget_grab_focus(toolbar->imhtml); | |
463 } | |
464 | |
465 | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
466 static void |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
467 close_smiley_dialog(GtkWidget *widget, GdkEvent *event, |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
468 GtkIMHtmlToolbar *toolbar) |
8317 | 469 { |
470 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
|
471 |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
472 if (toolbar->smiley_dialog != NULL) |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
473 { |
8317 | 474 gtk_widget_destroy(toolbar->smiley_dialog); |
475 toolbar->smiley_dialog = NULL; | |
476 } | |
477 } | |
478 | |
479 | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
480 static void |
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
481 insert_smiley_text(GtkWidget *widget, GtkIMHtmlToolbar *toolbar) |
8317 | 482 { |
483 char *smiley_text = g_object_get_data(G_OBJECT(widget), "smiley_text"); | |
484 | |
8456 | 485 gtk_imhtml_insert_smiley(GTK_IMHTML(toolbar->imhtml), |
486 GTK_IMHTML(toolbar->imhtml)->protocol_name, | |
487 smiley_text); | |
8317 | 488 |
8320
5c6c8d48946f
[gaim-migrate @ 9044]
Christian Hammond <chipx86@chipx86.com>
parents:
8319
diff
changeset
|
489 close_smiley_dialog(NULL, NULL, toolbar); |
8317 | 490 } |
491 | |
492 | |
493 static void add_smiley(GtkIMHtmlToolbar *toolbar, GtkWidget *table, int row, int col, char *filename, char *face) | |
494 { | |
495 GtkWidget *image; | |
496 GtkWidget *button; | |
497 | |
498 image = gtk_image_new_from_file(filename); | |
499 button = gtk_button_new(); | |
500 gtk_container_add(GTK_CONTAINER(button), image); | |
501 g_object_set_data(G_OBJECT(button), "smiley_text", face); | |
502 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(insert_smiley_text), toolbar); | |
503 | |
504 gtk_tooltips_set_tip(toolbar->tooltips, button, face, NULL); | |
505 | |
506 gtk_table_attach_defaults(GTK_TABLE(table), button, col, col+1, row, row+1); | |
507 | |
508 /* these look really weird with borders */ | |
509 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
510 | |
511 gtk_widget_show(button); | |
512 } | |
513 | |
514 | |
515 static gboolean smiley_is_unique(GSList *list, GtkIMHtmlSmiley *smiley) { | |
516 while(list) { | |
517 GtkIMHtmlSmiley *cur = list->data; | |
518 if(!strcmp(cur->file, smiley->file)) | |
519 return FALSE; | |
520 list = list->next; | |
521 } | |
522 return TRUE; | |
523 } | |
524 | |
525 | |
526 static void | |
527 insert_smiley_cb(GtkWidget *smiley, GtkIMHtmlToolbar *toolbar) | |
528 { | |
529 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(smiley))) { | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
530 |
8317 | 531 GtkWidget *dialog; |
532 GtkWidget *smiley_table = NULL; | |
533 GSList *smileys, *unique_smileys = NULL; | |
534 int width; | |
535 int row = 0, col = 0; | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
536 |
8317 | 537 if (toolbar->smiley_dialog) { |
538 gtk_widget_grab_focus(toolbar->imhtml); | |
539 return; | |
540 } | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
541 |
8427 | 542 if (toolbar->sml) |
543 smileys = get_proto_smileys(toolbar->sml); | |
8317 | 544 else |
8427 | 545 smileys = get_proto_smileys(GAIM_PROTO_DEFAULT); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
546 |
8317 | 547 while(smileys) { |
548 GtkIMHtmlSmiley *smiley = smileys->data; | |
549 if(!smiley->hidden) { | |
550 if(smiley_is_unique(unique_smileys, smiley)) | |
551 unique_smileys = g_slist_append(unique_smileys, smiley); | |
552 } | |
553 smileys = smileys->next; | |
554 } | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
555 |
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
556 |
8317 | 557 width = floor(sqrt(g_slist_length(unique_smileys))); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
558 |
8317 | 559 GAIM_DIALOG(dialog); |
560 gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); | |
561 gtk_window_set_role(GTK_WINDOW(dialog), "smiley_dialog"); | |
562 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
|
563 |
8317 | 564 smiley_table = gtk_table_new(width, width, TRUE); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
565 |
8317 | 566 /* pack buttons */ |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
567 |
8317 | 568 while(unique_smileys) { |
569 GtkIMHtmlSmiley *smiley = unique_smileys->data; | |
570 if(!smiley->hidden) { | |
571 add_smiley(toolbar, smiley_table, row, col, smiley->file, smiley->smile); | |
572 if(++col >= width) { | |
573 col = 0; | |
574 row++; | |
575 } | |
576 } | |
577 unique_smileys = unique_smileys->next; | |
578 } | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
579 |
8317 | 580 gtk_container_add(GTK_CONTAINER(dialog), smiley_table); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
581 |
8317 | 582 gtk_widget_show(smiley_table); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
583 |
8317 | 584 gtk_container_set_border_width(GTK_CONTAINER(dialog), 5); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
585 |
8317 | 586 /* connect signals */ |
587 g_object_set_data(G_OBJECT(dialog), "dialog_type", "smiley dialog"); | |
588 g_signal_connect(G_OBJECT(dialog), "delete_event", | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
589 G_CALLBACK(close_smiley_dialog), toolbar); |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
590 |
8317 | 591 /* show everything */ |
592 gtk_window_set_title(GTK_WINDOW(dialog), _("Smile!")); | |
593 gtk_widget_show_all(dialog); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
594 |
8317 | 595 toolbar->smiley_dialog = dialog; |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
596 |
8317 | 597 } else if (toolbar->smiley_dialog) { |
8320
5c6c8d48946f
[gaim-migrate @ 9044]
Christian Hammond <chipx86@chipx86.com>
parents:
8319
diff
changeset
|
598 close_smiley_dialog(smiley, NULL, toolbar); |
8317 | 599 } |
600 gtk_widget_grab_focus(toolbar->imhtml); | |
601 } | |
602 | |
8420 | 603 static void update_buttons_cb(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons, GtkIMHtmlToolbar *toolbar) |
604 { | |
605 | |
606 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->bold), buttons & GTK_IMHTML_BOLD); | |
607 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->italic), buttons & GTK_IMHTML_ITALIC); | |
608 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->underline), buttons & GTK_IMHTML_UNDERLINE); | |
609 | |
610 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->larger_size), buttons & GTK_IMHTML_GROW); | |
611 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->smaller_size), buttons & GTK_IMHTML_SHRINK); | |
612 | |
613 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->font), buttons & GTK_IMHTML_FACE); | |
614 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->fgcolor), buttons & GTK_IMHTML_FORECOLOR); | |
615 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->bgcolor), buttons & GTK_IMHTML_BACKCOLOR); | |
616 | |
617 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->image), buttons & GTK_IMHTML_IMAGE); | |
618 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->link), buttons & GTK_IMHTML_LINK); | |
619 gtk_widget_set_sensitive(GTK_WIDGET(toolbar->smiley), buttons & GTK_IMHTML_SMILEY); | |
620 | |
621 } | |
622 | |
623 static void toggle_button_cb(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons, GtkIMHtmlToolbar *toolbar) | |
624 { | |
625 /* This is hacky. I have to tolerate the fact that set_active causes the signal to be emited, so I wind up | |
626 * toggling in gtkimhtml twice here */ | |
627 | |
628 if (buttons & GTK_IMHTML_BOLD) { | |
629 gtk_imhtml_toggle_bold(imhtml); | |
630 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->bold), !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->bold))); | |
631 } | |
632 | |
633 if (buttons & GTK_IMHTML_ITALIC) { | |
634 gtk_imhtml_toggle_italic(imhtml); | |
635 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->italic), !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->italic))); | |
636 } | |
637 | |
638 if (buttons & GTK_IMHTML_UNDERLINE) { | |
639 gtk_imhtml_toggle_underline(imhtml); | |
640 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->underline), !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar->underline))); | |
641 } | |
642 } | |
643 | |
8427 | 644 static void reset_buttons_cb(GtkIMHtml *imhtml, GtkIMHtmlToolbar *toolbar) |
645 { | |
646 printf("yo!\n"); | |
647 } | |
648 | |
8317 | 649 enum { |
650 LAST_SIGNAL | |
651 }; | |
652 //static guint signals [LAST_SIGNAL] = { 0 }; | |
653 | |
654 static void | |
655 gtk_imhtmltoolbar_finalize (GObject *object) | |
656 { | |
8391 | 657 GtkIMHtmlToolbar *toolbar = GTK_IMHTMLTOOLBAR(object); |
8317 | 658 |
8447 | 659 if (toolbar->smiley_dialog != NULL) |
660 { | |
661 gtk_widget_destroy(toolbar->smiley_dialog); | |
662 toolbar->smiley_dialog = NULL; | |
663 } | |
664 | |
8427 | 665 if (toolbar->sml) |
666 free(toolbar->sml); | |
8391 | 667 gtk_object_sink(GTK_OBJECT(toolbar->tooltips)); |
8317 | 668 |
8391 | 669 G_OBJECT_CLASS(parent_class)->finalize (object); |
8317 | 670 } |
671 | |
672 /* Boring GTK stuff */ | |
673 static void gtk_imhtmltoolbar_class_init (GtkIMHtmlToolbarClass *class) | |
674 { | |
675 GtkObjectClass *object_class; | |
676 GObjectClass *gobject_class; | |
677 object_class = (GtkObjectClass*) class; | |
678 gobject_class = (GObjectClass*) class; | |
679 parent_class = gtk_type_class(GTK_TYPE_VBOX); | |
680 /* signals[URL_CLICKED] = g_signal_new(url_clicked", | |
681 G_TYPE_FROM_CLASS(gobject_class), | |
682 G_SIGNAL_RUN_FIRST, | |
683 G_STRUCT_OFFSET(GtkIMHtmlClass, url_clicked), | |
684 NULL, | |
685 0, | |
686 g_cclosure_marshal_VOID__POINTER, | |
687 G_TYPE_NONE, 1, | |
688 G_TYPE_POINTER);*/ | |
689 gobject_class->finalize = gtk_imhtmltoolbar_finalize; | |
690 } | |
691 | |
692 static void gtk_imhtmltoolbar_init (GtkIMHtmlToolbar *toolbar) | |
693 { | |
694 GtkWidget *hbox; | |
695 GtkWidget *button; | |
696 GtkWidget *sep; | |
697 GtkSizeGroup *sg; | |
698 | |
699 toolbar->imhtml = NULL; | |
700 toolbar->font_dialog = NULL; | |
701 toolbar->fgcolor_dialog = NULL; | |
702 toolbar->bgcolor_dialog = NULL; | |
703 toolbar->link_dialog = NULL; | |
704 toolbar->smiley_dialog = NULL; | |
705 toolbar->image_dialog = NULL; | |
706 | |
707 toolbar->tooltips = gtk_tooltips_new(); | |
708 | |
709 sg = gtk_size_group_new(GTK_SIZE_GROUP_BOTH); | |
710 | |
711 sep = gtk_hseparator_new(); | |
712 gtk_box_pack_start(GTK_BOX(toolbar), sep, FALSE, FALSE, 0); | |
713 gtk_widget_show(sep); | |
714 | |
715 hbox = gtk_hbox_new(FALSE, 6); | |
716 gtk_box_pack_start(GTK_BOX(toolbar), hbox, FALSE, FALSE, 0); | |
717 | |
718 /* Bold */ | |
719 button = gaim_pixbuf_toolbar_button_from_stock(GTK_STOCK_BOLD); | |
720 gtk_size_group_add_widget(sg, button); | |
721 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
722 gtk_tooltips_set_tip(toolbar->tooltips, button, _("Bold"), NULL); | |
723 | |
724 g_signal_connect(G_OBJECT(button), "clicked", | |
725 G_CALLBACK(do_bold), toolbar); | |
726 | |
727 toolbar->bold = button; | |
728 | |
729 /* Italic */ | |
730 button = gaim_pixbuf_toolbar_button_from_stock(GTK_STOCK_ITALIC); | |
731 gtk_size_group_add_widget(sg, button); | |
732 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
733 gtk_tooltips_set_tip(toolbar->tooltips, button, _("Italic"), NULL); | |
734 | |
735 g_signal_connect(G_OBJECT(button), "clicked", | |
736 G_CALLBACK(do_italic), toolbar); | |
737 | |
738 toolbar->italic = button; | |
739 | |
740 /* Underline */ | |
741 button = gaim_pixbuf_toolbar_button_from_stock(GTK_STOCK_UNDERLINE); | |
742 gtk_size_group_add_widget(sg, button); | |
743 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
744 gtk_tooltips_set_tip(toolbar->tooltips, button, _("Underline"), NULL); | |
745 | |
746 g_signal_connect(G_OBJECT(button), "clicked", | |
747 G_CALLBACK(do_underline), toolbar); | |
748 | |
749 toolbar->underline = button; | |
750 | |
751 /* Sep */ | |
752 sep = gtk_vseparator_new(); | |
753 gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0); | |
754 | |
755 /* Increase font size */ | |
756 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_TEXT_BIGGER); | |
757 gtk_size_group_add_widget(sg, button); | |
758 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
759 gtk_tooltips_set_tip(toolbar->tooltips, button, | |
760 _("Larger font size"), NULL); | |
761 | |
762 g_signal_connect(G_OBJECT(button), "clicked", | |
763 G_CALLBACK(do_big), toolbar); | |
764 | |
765 toolbar->larger_size = button; | |
766 | |
767 /* Decrease font size */ | |
768 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_TEXT_SMALLER); | |
769 gtk_size_group_add_widget(sg, button); | |
770 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
771 gtk_tooltips_set_tip(toolbar->tooltips, button, | |
772 _("Smaller font size"), NULL); | |
773 | |
774 g_signal_connect(G_OBJECT(button), "clicked", | |
775 G_CALLBACK(do_small), toolbar); | |
776 | |
777 toolbar->smaller_size = button; | |
778 | |
779 /* Sep */ | |
780 sep = gtk_vseparator_new(); | |
781 gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0); | |
782 | |
783 /* Font Face */ | |
784 | |
785 button = gaim_pixbuf_toolbar_button_from_stock(GTK_STOCK_SELECT_FONT); | |
786 gtk_size_group_add_widget(sg, button); | |
787 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
788 gtk_tooltips_set_tip(toolbar->tooltips, button, | |
789 _("Font Face"), NULL); | |
790 | |
791 g_signal_connect(G_OBJECT(button), "clicked", | |
792 G_CALLBACK(toggle_font), toolbar); | |
793 | |
794 toolbar->font = button; | |
795 | |
796 /* Foreground Color */ | |
797 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_FGCOLOR); | |
798 gtk_size_group_add_widget(sg, button); | |
799 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
800 gtk_tooltips_set_tip(toolbar->tooltips, button, | |
801 _("Foreground font color"), NULL); | |
802 | |
803 g_signal_connect(G_OBJECT(button), "clicked", | |
804 G_CALLBACK(toggle_fg_color), toolbar); | |
805 | |
806 toolbar->fgcolor = button; | |
807 | |
808 /* Background Color */ | |
809 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_BGCOLOR); | |
810 gtk_size_group_add_widget(sg, button); | |
811 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
812 gtk_tooltips_set_tip(toolbar->tooltips, button, | |
813 _("Background color"), NULL); | |
814 | |
815 g_signal_connect(G_OBJECT(button), "clicked", | |
816 G_CALLBACK(toggle_bg_color), toolbar); | |
817 | |
818 toolbar->bgcolor = button; | |
819 | |
820 /* Sep */ | |
821 sep = gtk_vseparator_new(); | |
822 gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0); | |
823 | |
824 /* Insert Link */ | |
825 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_LINK); | |
826 gtk_size_group_add_widget(sg, button); | |
827 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
828 gtk_tooltips_set_tip(toolbar->tooltips, button, _("Insert link"), NULL); | |
829 g_signal_connect(G_OBJECT(button), "clicked", | |
830 G_CALLBACK(insert_link_cb), toolbar); | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
831 |
8317 | 832 toolbar->link = button; |
833 | |
834 /* Insert IM Image */ | |
835 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_IMAGE); | |
836 gtk_size_group_add_widget(sg, button); | |
837 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
838 gtk_tooltips_set_tip(toolbar->tooltips, button, _("Insert image"), NULL); | |
839 | |
840 g_signal_connect(G_OBJECT(button), "clicked", | |
841 G_CALLBACK(insert_image_cb), toolbar); | |
842 | |
843 toolbar->image = button; | |
844 | |
845 /* Insert Smiley */ | |
846 button = gaim_pixbuf_toolbar_button_from_stock(GAIM_STOCK_SMILEY); | |
847 gtk_size_group_add_widget(sg, button); | |
848 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
849 gtk_tooltips_set_tip(toolbar->tooltips, button, _("Insert smiley"), NULL); | |
850 | |
851 g_signal_connect(G_OBJECT(button), "clicked", | |
852 G_CALLBACK(insert_smiley_cb), toolbar); | |
853 | |
854 toolbar->smiley = button; | |
855 | |
856 | |
857 sep = gtk_hseparator_new(); | |
858 gtk_box_pack_start(GTK_BOX(toolbar), sep, FALSE, FALSE, 0); | |
859 gtk_widget_show(sep); | |
8427 | 860 toolbar->sml = NULL; |
8317 | 861 gtk_widget_show_all(hbox); |
862 } | |
863 | |
864 GtkWidget *gtk_imhtmltoolbar_new() | |
865 { | |
866 return GTK_WIDGET(g_object_new(gtk_imhtmltoolbar_get_type(), NULL)); | |
867 } | |
868 | |
869 GType gtk_imhtmltoolbar_get_type() | |
870 { | |
871 static GType imhtmltoolbar_type = 0; | |
872 | |
873 if (!imhtmltoolbar_type) { | |
874 static const GTypeInfo imhtmltoolbar_info = { | |
875 sizeof(GtkIMHtmlToolbarClass), | |
876 NULL, | |
877 NULL, | |
878 (GClassInitFunc) gtk_imhtmltoolbar_class_init, | |
879 NULL, | |
880 NULL, | |
881 sizeof (GtkIMHtmlToolbar), | |
882 0, | |
883 (GInstanceInitFunc) gtk_imhtmltoolbar_init | |
884 }; | |
885 | |
8319
a2c5537a814b
[gaim-migrate @ 9043]
Christian Hammond <chipx86@chipx86.com>
parents:
8317
diff
changeset
|
886 imhtmltoolbar_type = g_type_register_static(GTK_TYPE_VBOX, |
8317 | 887 "GtkIMHtmlToolbar", &imhtmltoolbar_info, 0); |
888 } | |
889 | |
890 return imhtmltoolbar_type; | |
891 } | |
892 | |
893 | |
8324
2df8b01af581
[gaim-migrate @ 9048]
Christian Hammond <chipx86@chipx86.com>
parents:
8322
diff
changeset
|
894 void gtk_imhtmltoolbar_attach(GtkIMHtmlToolbar *toolbar, GtkWidget *imhtml) |
8317 | 895 { |
8325
415283e39bce
[gaim-migrate @ 9049]
Christian Hammond <chipx86@chipx86.com>
parents:
8324
diff
changeset
|
896 g_return_if_fail(toolbar != NULL); |
415283e39bce
[gaim-migrate @ 9049]
Christian Hammond <chipx86@chipx86.com>
parents:
8324
diff
changeset
|
897 g_return_if_fail(GTK_IS_IMHTMLTOOLBAR(toolbar)); |
415283e39bce
[gaim-migrate @ 9049]
Christian Hammond <chipx86@chipx86.com>
parents:
8324
diff
changeset
|
898 g_return_if_fail(imhtml != NULL); |
415283e39bce
[gaim-migrate @ 9049]
Christian Hammond <chipx86@chipx86.com>
parents:
8324
diff
changeset
|
899 g_return_if_fail(GTK_IS_IMHTML(imhtml)); |
415283e39bce
[gaim-migrate @ 9049]
Christian Hammond <chipx86@chipx86.com>
parents:
8324
diff
changeset
|
900 |
8317 | 901 toolbar->imhtml = imhtml; |
8420 | 902 g_signal_connect(G_OBJECT(imhtml), "format_functions_update", G_CALLBACK(update_buttons_cb), toolbar); |
903 g_signal_connect(G_OBJECT(imhtml), "format_function_toggle", G_CALLBACK(toggle_button_cb), toolbar); | |
8427 | 904 g_signal_connect(G_OBJECT(imhtml), "format_function_clear", G_CALLBACK(reset_buttons_cb), toolbar); |
8317 | 905 } |
8427 | 906 |
907 void gtk_imhtmltoolbar_associate_smileys(GtkIMHtmlToolbar *toolbar, const char *proto_id) | |
908 { | |
909 if (toolbar->sml) | |
910 g_free(toolbar->sml); | |
911 | |
912 toolbar->sml = g_strdup(proto_id); | |
913 } |