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