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