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