2 * @file gtkimhtmltoolbar.c GTK+ IMHtml Toolbar
8 * Pidgin is the legal property of its developers, whose names are too numerous
9 * to list here. Please refer to the COPYRIGHT file distributed with this
10 * source distribution.
12 * This program is free software; you can redistribute it and/or modify
13 * under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
34 #include "pidginstock.h"
37 #include "gtkdialogs.h"
38 #include "gtkimhtmltoolbar.h"
39 #include "gtkthemes.h"
42 #include <gdk/gdkkeysyms.h>
44 static GtkHBoxClass
*parent_class
= NULL
;
46 static void toggle_button_set_active_block(GtkToggleButton
*button
,
48 GtkIMHtmlToolbar
*toolbar
);
51 static void do_bold(GtkWidget
*bold
, GtkIMHtmlToolbar
*toolbar
)
53 g_return_if_fail(toolbar
!= NULL
);
54 gtk_imhtml_toggle_bold(GTK_IMHTML(toolbar
->imhtml
));
55 gtk_widget_grab_focus(toolbar
->imhtml
);
59 do_italic(GtkWidget
*italic
, GtkIMHtmlToolbar
*toolbar
)
61 g_return_if_fail(toolbar
!= NULL
);
62 gtk_imhtml_toggle_italic(GTK_IMHTML(toolbar
->imhtml
));
63 gtk_widget_grab_focus(toolbar
->imhtml
);
67 do_underline(GtkWidget
*underline
, GtkIMHtmlToolbar
*toolbar
)
69 g_return_if_fail(toolbar
!= NULL
);
70 gtk_imhtml_toggle_underline(GTK_IMHTML(toolbar
->imhtml
));
71 gtk_widget_grab_focus(toolbar
->imhtml
);
75 do_strikethrough(GtkWidget
*strikethrough
, GtkIMHtmlToolbar
*toolbar
)
77 g_return_if_fail(toolbar
!= NULL
);
78 gtk_imhtml_toggle_strike(GTK_IMHTML(toolbar
->imhtml
));
79 gtk_widget_grab_focus(toolbar
->imhtml
);
83 do_small(GtkWidget
*smalltb
, GtkIMHtmlToolbar
*toolbar
)
85 g_return_if_fail(toolbar
!= NULL
);
86 /* Only shrink the font on activation, not deactivation as well */
87 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(smalltb
)))
88 gtk_imhtml_font_shrink(GTK_IMHTML(toolbar
->imhtml
));
89 gtk_widget_grab_focus(toolbar
->imhtml
);
93 do_big(GtkWidget
*large
, GtkIMHtmlToolbar
*toolbar
)
95 g_return_if_fail(toolbar
);
96 /* Only grow the font on activation, not deactivation as well */
97 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(large
)))
98 gtk_imhtml_font_grow(GTK_IMHTML(toolbar
->imhtml
));
99 gtk_widget_grab_focus(toolbar
->imhtml
);
103 destroy_toolbar_font(GtkWidget
*widget
, GdkEvent
*event
,
104 GtkIMHtmlToolbar
*toolbar
)
107 gtk_imhtml_toggle_fontface(GTK_IMHTML(toolbar
->imhtml
), "");
109 if (toolbar
->font_dialog
!= NULL
)
111 gtk_widget_destroy(toolbar
->font_dialog
);
112 toolbar
->font_dialog
= NULL
;
117 realize_toolbar_font(GtkWidget
*widget
, GtkIMHtmlToolbar
*toolbar
)
119 GtkFontSelection
*sel
;
121 sel
= GTK_FONT_SELECTION(GTK_FONT_SELECTION_DIALOG(toolbar
->font_dialog
)->fontsel
);
122 gtk_widget_hide_all(gtk_widget_get_parent(sel
->size_entry
));
123 gtk_widget_show_all(sel
->family_list
);
124 gtk_widget_show(gtk_widget_get_parent(sel
->family_list
));
125 gtk_widget_show(gtk_widget_get_parent(gtk_widget_get_parent(sel
->family_list
)));
129 cancel_toolbar_font(GtkWidget
*widget
, GtkIMHtmlToolbar
*toolbar
)
131 destroy_toolbar_font(widget
, NULL
, toolbar
);
134 static void apply_font(GtkWidget
*widget
, GtkFontSelection
*fontsel
)
136 /* this could be expanded to include font size, weight, etc.
137 but for now only works with font face */
140 GtkIMHtmlToolbar
*toolbar
= g_object_get_data(G_OBJECT(fontsel
), "purple_toolbar");
142 fontname
= gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(fontsel
));
144 space
= strrchr(fontname
, ' ');
145 if(space
&& isdigit(*(space
+1)))
148 gtk_imhtml_toggle_fontface(GTK_IMHTML(toolbar
->imhtml
), fontname
);
151 cancel_toolbar_font(NULL
, toolbar
);
155 toggle_font(GtkWidget
*font
, GtkIMHtmlToolbar
*toolbar
)
157 g_return_if_fail(toolbar
);
159 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(font
))) {
160 char *fontname
= gtk_imhtml_get_current_fontface(GTK_IMHTML(toolbar
->imhtml
));
162 if (!toolbar
->font_dialog
) {
163 toolbar
->font_dialog
= gtk_font_selection_dialog_new(_("Select Font"));
165 g_object_set_data(G_OBJECT(toolbar
->font_dialog
), "purple_toolbar", toolbar
);
168 char *fonttif
= g_strdup_printf("%s 12", fontname
);
170 gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(toolbar
->font_dialog
),
174 gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(toolbar
->font_dialog
),
178 g_signal_connect(G_OBJECT(toolbar
->font_dialog
), "delete_event",
179 G_CALLBACK(destroy_toolbar_font
), toolbar
);
180 g_signal_connect(G_OBJECT(GTK_FONT_SELECTION_DIALOG(toolbar
->font_dialog
)->ok_button
), "clicked",
181 G_CALLBACK(apply_font
), toolbar
->font_dialog
);
182 g_signal_connect(G_OBJECT(GTK_FONT_SELECTION_DIALOG(toolbar
->font_dialog
)->cancel_button
), "clicked",
183 G_CALLBACK(cancel_toolbar_font
), toolbar
);
184 g_signal_connect_after(G_OBJECT(toolbar
->font_dialog
), "realize",
185 G_CALLBACK(realize_toolbar_font
), toolbar
);
187 gtk_window_present(GTK_WINDOW(toolbar
->font_dialog
));
189 cancel_toolbar_font(font
, toolbar
);
191 gtk_widget_grab_focus(toolbar
->imhtml
);
195 destroy_toolbar_fgcolor(GtkWidget
*widget
, GdkEvent
*event
,
196 GtkIMHtmlToolbar
*toolbar
)
199 gtk_imhtml_toggle_forecolor(GTK_IMHTML(toolbar
->imhtml
), "");
201 if (toolbar
->fgcolor_dialog
!= NULL
)
203 gtk_widget_destroy(toolbar
->fgcolor_dialog
);
204 toolbar
->fgcolor_dialog
= NULL
;
208 static void cancel_toolbar_fgcolor(GtkWidget
*widget
,
209 GtkIMHtmlToolbar
*toolbar
)
211 destroy_toolbar_fgcolor(widget
, NULL
, toolbar
);
214 static void do_fgcolor(GtkWidget
*widget
, GtkColorSelection
*colorsel
)
217 GtkIMHtmlToolbar
*toolbar
= g_object_get_data(G_OBJECT(colorsel
), "purple_toolbar");
220 open_tag
= g_malloc(30);
221 gtk_color_selection_get_current_color(colorsel
, &text_color
);
222 g_snprintf(open_tag
, 23, "#%02X%02X%02X",
223 text_color
.red
/ 256,
224 text_color
.green
/ 256,
225 text_color
.blue
/ 256);
226 gtk_imhtml_toggle_forecolor(GTK_IMHTML(toolbar
->imhtml
), open_tag
);
229 cancel_toolbar_fgcolor(NULL
, toolbar
);
233 toggle_fg_color(GtkWidget
*color
, GtkIMHtmlToolbar
*toolbar
)
235 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(color
))) {
238 char *color
= gtk_imhtml_get_current_forecolor(GTK_IMHTML(toolbar
->imhtml
));
240 if (!toolbar
->fgcolor_dialog
) {
242 toolbar
->fgcolor_dialog
= gtk_color_selection_dialog_new(_("Select Text Color"));
243 colorsel
= GTK_COLOR_SELECTION_DIALOG(toolbar
->fgcolor_dialog
)->colorsel
;
245 gdk_color_parse(color
, &fgcolor
);
246 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel
), &fgcolor
);
250 g_object_set_data(G_OBJECT(colorsel
), "purple_toolbar", toolbar
);
252 g_signal_connect(G_OBJECT(toolbar
->fgcolor_dialog
), "delete_event",
253 G_CALLBACK(destroy_toolbar_fgcolor
), toolbar
);
254 g_signal_connect(G_OBJECT(GTK_COLOR_SELECTION_DIALOG(toolbar
->fgcolor_dialog
)->ok_button
), "clicked",
255 G_CALLBACK(do_fgcolor
), colorsel
);
256 g_signal_connect(G_OBJECT (GTK_COLOR_SELECTION_DIALOG(toolbar
->fgcolor_dialog
)->cancel_button
), "clicked",
257 G_CALLBACK(cancel_toolbar_fgcolor
), toolbar
);
259 gtk_window_present(GTK_WINDOW(toolbar
->fgcolor_dialog
));
261 cancel_toolbar_fgcolor(color
, toolbar
);
263 gtk_widget_grab_focus(toolbar
->imhtml
);
267 destroy_toolbar_bgcolor(GtkWidget
*widget
, GdkEvent
*event
,
268 GtkIMHtmlToolbar
*toolbar
)
270 if (widget
!= NULL
) {
271 if (gtk_text_buffer_get_selection_bounds(GTK_IMHTML(toolbar
->imhtml
)->text_buffer
, NULL
, NULL
))
272 gtk_imhtml_toggle_backcolor(GTK_IMHTML(toolbar
->imhtml
), "");
274 gtk_imhtml_toggle_background(GTK_IMHTML(toolbar
->imhtml
), "");
277 if (toolbar
->bgcolor_dialog
!= NULL
)
279 gtk_widget_destroy(toolbar
->bgcolor_dialog
);
280 toolbar
->bgcolor_dialog
= NULL
;
285 cancel_toolbar_bgcolor(GtkWidget
*widget
, GtkIMHtmlToolbar
*toolbar
)
287 destroy_toolbar_bgcolor(widget
, NULL
, toolbar
);
290 static void do_bgcolor(GtkWidget
*widget
, GtkColorSelection
*colorsel
)
293 GtkIMHtmlToolbar
*toolbar
= g_object_get_data(G_OBJECT(colorsel
), "purple_toolbar");
296 open_tag
= g_malloc(30);
297 gtk_color_selection_get_current_color(colorsel
, &text_color
);
298 g_snprintf(open_tag
, 23, "#%02X%02X%02X",
299 text_color
.red
/ 256,
300 text_color
.green
/ 256,
301 text_color
.blue
/ 256);
302 if (gtk_text_buffer_get_selection_bounds(GTK_IMHTML(toolbar
->imhtml
)->text_buffer
, NULL
, NULL
))
303 gtk_imhtml_toggle_backcolor(GTK_IMHTML(toolbar
->imhtml
), open_tag
);
305 gtk_imhtml_toggle_background(GTK_IMHTML(toolbar
->imhtml
), open_tag
);
308 cancel_toolbar_bgcolor(NULL
, toolbar
);
312 toggle_bg_color(GtkWidget
*color
, GtkIMHtmlToolbar
*toolbar
)
314 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(color
))) {
317 char *color
= gtk_imhtml_get_current_backcolor(GTK_IMHTML(toolbar
->imhtml
));
319 if (!toolbar
->bgcolor_dialog
) {
321 toolbar
->bgcolor_dialog
= gtk_color_selection_dialog_new(_("Select Background Color"));
322 colorsel
= GTK_COLOR_SELECTION_DIALOG(toolbar
->bgcolor_dialog
)->colorsel
;
324 gdk_color_parse(color
, &bgcolor
);
325 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel
), &bgcolor
);
329 g_object_set_data(G_OBJECT(colorsel
), "purple_toolbar", toolbar
);
331 g_signal_connect(G_OBJECT(toolbar
->bgcolor_dialog
), "delete_event",
332 G_CALLBACK(destroy_toolbar_bgcolor
), toolbar
);
333 g_signal_connect(G_OBJECT(GTK_COLOR_SELECTION_DIALOG(toolbar
->bgcolor_dialog
)->ok_button
), "clicked",
334 G_CALLBACK(do_bgcolor
), colorsel
);
335 g_signal_connect(G_OBJECT(GTK_COLOR_SELECTION_DIALOG(toolbar
->bgcolor_dialog
)->cancel_button
), "clicked",
336 G_CALLBACK(cancel_toolbar_bgcolor
), toolbar
);
339 gtk_window_present(GTK_WINDOW(toolbar
->bgcolor_dialog
));
341 cancel_toolbar_bgcolor(color
, toolbar
);
343 gtk_widget_grab_focus(toolbar
->imhtml
);
347 clear_formatting_cb(GtkWidget
*clear
, GtkIMHtmlToolbar
*toolbar
)
349 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar
->clear
), FALSE
, toolbar
);
350 gtk_imhtml_clear_formatting(GTK_IMHTML(toolbar
->imhtml
));
354 cancel_link_cb(GtkIMHtmlToolbar
*toolbar
, PurpleRequestFields
*fields
)
356 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar
->link
), FALSE
);
358 toolbar
->link_dialog
= NULL
;
362 close_link_dialog(GtkIMHtmlToolbar
*toolbar
)
364 if (toolbar
->link_dialog
!= NULL
)
366 purple_request_close(PURPLE_REQUEST_FIELDS
, toolbar
->link_dialog
);
367 toolbar
->link_dialog
= NULL
;
372 do_insert_link_cb(GtkIMHtmlToolbar
*toolbar
, PurpleRequestFields
*fields
)
374 const char *url
, *description
;
376 url
= purple_request_fields_get_string(fields
, "url");
377 if (GTK_IMHTML(toolbar
->imhtml
)->format_functions
& GTK_IMHTML_LINKDESC
)
378 description
= purple_request_fields_get_string(fields
, "description");
382 if (description
== NULL
)
385 gtk_imhtml_insert_link(GTK_IMHTML(toolbar
->imhtml
),
386 gtk_text_buffer_get_insert(GTK_IMHTML(toolbar
->imhtml
)->text_buffer
),
389 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar
->link
), FALSE
);
391 toolbar
->link_dialog
= NULL
;
395 insert_link_cb(GtkWidget
*w
, GtkIMHtmlToolbar
*toolbar
)
397 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar
->link
))) {
398 PurpleRequestFields
*fields
;
399 PurpleRequestFieldGroup
*group
;
400 PurpleRequestField
*field
;
401 GtkTextIter start
, end
;
405 fields
= purple_request_fields_new();
407 group
= purple_request_field_group_new(NULL
);
408 purple_request_fields_add_group(fields
, group
);
410 field
= purple_request_field_string_new("url", _("_URL"), NULL
, FALSE
);
411 purple_request_field_set_required(field
, TRUE
);
412 purple_request_field_group_add_field(group
, field
);
414 if(GTK_IMHTML(toolbar
->imhtml
)->format_functions
& GTK_IMHTML_LINKDESC
) {
415 if (gtk_text_buffer_get_selection_bounds(GTK_IMHTML(toolbar
->imhtml
)->text_buffer
, &start
, &end
)) {
416 desc
= gtk_imhtml_get_text(GTK_IMHTML(toolbar
->imhtml
), &start
, &end
);
418 field
= purple_request_field_string_new("description", _("_Description"),
420 purple_request_field_group_add_field(group
, field
);
421 msg
= g_strdup(_("Please enter the URL and description of the "
422 "link that you want to insert. The description "
425 msg
= g_strdup(_("Please enter the URL of the "
426 "link that you want to insert."));
429 toolbar
->link_dialog
=
430 purple_request_fields(toolbar
, _("Insert Link"),
434 _("_Insert"), G_CALLBACK(do_insert_link_cb
),
435 _("Cancel"), G_CALLBACK(cancel_link_cb
),
441 close_link_dialog(toolbar
);
443 gtk_widget_grab_focus(toolbar
->imhtml
);
446 static void insert_hr_cb(GtkWidget
*widget
, GtkIMHtmlToolbar
*toolbar
)
450 GtkIMHtmlScalable
*hr
;
452 ins
= gtk_text_buffer_get_insert(gtk_text_view_get_buffer(GTK_TEXT_VIEW(toolbar
->imhtml
)));
453 gtk_text_buffer_get_iter_at_mark(gtk_text_view_get_buffer(GTK_TEXT_VIEW(toolbar
->imhtml
)), &iter
, ins
);
454 hr
= gtk_imhtml_hr_new();
455 gtk_imhtml_hr_add_to(hr
, GTK_IMHTML(toolbar
->imhtml
), &iter
);
459 do_insert_image_cb(GtkWidget
*widget
, int response
, GtkIMHtmlToolbar
*toolbar
)
461 gchar
*filename
, *name
, *buf
;
464 GError
*error
= NULL
;
469 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
470 if (response
!= GTK_RESPONSE_ACCEPT
) {
471 #else /* FILECHOOSER */
472 if (response
!= GTK_RESPONSE_OK
) {
473 #endif /* FILECHOOSER */
474 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar
->image
), FALSE
);
478 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
479 filename
= gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget
));
480 #else /* FILECHOOSER */
481 filename
= g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(widget
)));
482 #endif /* FILECHOOSER */
484 if (filename
== NULL
) {
485 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar
->image
), FALSE
);
489 #if !GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
490 if (pidgin_check_if_dir(filename
, GTK_FILE_SELECTION(widget
))) {
492 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar
->image
), FALSE
);
495 #endif /* FILECHOOSER */
497 /* The following triggers a callback that closes the widget */
498 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar
->image
), FALSE
);
500 if (!g_file_get_contents(filename
, &filedata
, &size
, &error
)) {
501 purple_notify_error(NULL
, NULL
, error
->message
, NULL
);
509 name
= strrchr(filename
, G_DIR_SEPARATOR
) + 1;
511 id
= purple_imgstore_add_with_id(filedata
, size
, name
);
514 buf
= g_strdup_printf(_("Failed to store image: %s\n"), filename
);
515 purple_notify_error(NULL
, NULL
, buf
, NULL
);
525 ins
= gtk_text_buffer_get_insert(gtk_text_view_get_buffer(GTK_TEXT_VIEW(toolbar
->imhtml
)));
526 gtk_text_buffer_get_iter_at_mark(gtk_text_view_get_buffer(GTK_TEXT_VIEW(toolbar
->imhtml
)),
528 gtk_imhtml_insert_image_at_iter(GTK_IMHTML(toolbar
->imhtml
), id
, &iter
);
529 purple_imgstore_unref_by_id(id
);
534 insert_image_cb(GtkWidget
*save
, GtkIMHtmlToolbar
*toolbar
)
538 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar
->image
))) {
539 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
540 window
= gtk_file_chooser_dialog_new(_("Insert Image"),
542 GTK_FILE_CHOOSER_ACTION_OPEN
,
543 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
544 GTK_STOCK_OPEN
, GTK_RESPONSE_ACCEPT
,
546 gtk_dialog_set_default_response(GTK_DIALOG(window
), GTK_RESPONSE_ACCEPT
);
547 g_signal_connect(G_OBJECT(GTK_FILE_CHOOSER(window
)),
548 "response", G_CALLBACK(do_insert_image_cb
), toolbar
);
549 #else /* FILECHOOSER */
550 window
= gtk_file_selection_new(_("Insert Image"));
551 gtk_dialog_set_default_response(GTK_DIALOG(window
), GTK_RESPONSE_OK
);
552 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(window
)),
553 "response", G_CALLBACK(do_insert_image_cb
), toolbar
);
554 #endif /* FILECHOOSER */
556 gtk_widget_show(window
);
557 toolbar
->image_dialog
= window
;
559 gtk_widget_destroy(toolbar
->image_dialog
);
560 toolbar
->image_dialog
= NULL
;
563 gtk_widget_grab_focus(toolbar
->imhtml
);
568 destroy_smiley_dialog(GtkIMHtmlToolbar
*toolbar
)
570 if (toolbar
->smiley_dialog
!= NULL
)
572 gtk_widget_destroy(toolbar
->smiley_dialog
);
573 toolbar
->smiley_dialog
= NULL
;
578 close_smiley_dialog(GtkWidget
*widget
, GdkEvent
*event
,
579 GtkIMHtmlToolbar
*toolbar
)
581 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar
->smiley
), FALSE
);
586 insert_smiley_text(GtkWidget
*widget
, GtkIMHtmlToolbar
*toolbar
)
588 char *smiley_text
, *escaped_smiley
;
590 smiley_text
= g_object_get_data(G_OBJECT(widget
), "smiley_text");
591 escaped_smiley
= g_markup_escape_text(smiley_text
, -1);
593 gtk_imhtml_insert_smiley(GTK_IMHTML(toolbar
->imhtml
),
594 GTK_IMHTML(toolbar
->imhtml
)->protocol_name
,
597 g_free(escaped_smiley
);
599 close_smiley_dialog(NULL
, NULL
, toolbar
);
602 /* smiley buttons list */
603 struct smiley_button_list
{
606 struct smiley_button_list
*next
;
609 static struct smiley_button_list
*
610 sort_smileys(struct smiley_button_list
*ls
, GtkIMHtmlToolbar
*toolbar
, int *width
, char *filename
, char *face
)
615 struct smiley_button_list
*cur
;
616 struct smiley_button_list
*it
, *it_last
;
618 cur
= malloc(sizeof(struct smiley_button_list
));
620 it_last
= ls
; /* list iterators*/
621 image
= gtk_image_new_from_file(filename
);
623 gtk_widget_size_request(image
, &size
);
624 (*width
) += size
.width
;
626 button
= gtk_button_new();
627 gtk_container_add(GTK_CONTAINER(button
), image
);
629 g_object_set_data(G_OBJECT(button
), "smiley_text", face
);
630 g_signal_connect(G_OBJECT(button
), "clicked", G_CALLBACK(insert_smiley_text
), toolbar
);
632 gtk_tooltips_set_tip(toolbar
->tooltips
, button
, face
, NULL
);
634 /* these look really weird with borders */
635 gtk_button_set_relief(GTK_BUTTON(button
), GTK_RELIEF_NONE
);
637 /* set current element to add */
638 cur
->height
= size
.height
;
639 cur
->width
= size
.width
;
640 cur
->button
= button
;
643 /* check where to insert by height */
656 smiley_is_unique(GSList
*list
, GtkIMHtmlSmiley
*smiley
)
659 GtkIMHtmlSmiley
*cur
= list
->data
;
660 if (!strcmp(cur
->file
, smiley
->file
))
668 smiley_dialog_input_cb(GtkWidget
*dialog
, GdkEvent
*event
, GtkIMHtmlToolbar
*toolbar
)
670 if ((event
->type
== GDK_KEY_PRESS
&& event
->key
.keyval
== GDK_Escape
) ||
671 (event
->type
== GDK_BUTTON_PRESS
&& event
->button
.button
== 1))
673 close_smiley_dialog(NULL
, NULL
, toolbar
);
681 insert_smiley_cb(GtkWidget
*smiley
, GtkIMHtmlToolbar
*toolbar
)
684 GtkWidget
*smiley_table
= NULL
;
685 GSList
*smileys
, *unique_smileys
= NULL
;
687 if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(smiley
))) {
688 destroy_smiley_dialog(toolbar
);
689 gtk_widget_grab_focus(toolbar
->imhtml
);
694 smileys
= pidgin_themes_get_proto_smileys(toolbar
->sml
);
696 smileys
= pidgin_themes_get_proto_smileys(NULL
);
699 GtkIMHtmlSmiley
*smiley
= smileys
->data
;
700 if(!smiley
->hidden
) {
701 if(smiley_is_unique(unique_smileys
, smiley
))
702 unique_smileys
= g_slist_append(unique_smileys
, smiley
);
704 smileys
= smileys
->next
;
707 PIDGIN_DIALOG(dialog
);
709 gtk_window_set_resizable(GTK_WINDOW(dialog
), FALSE
);
710 gtk_window_set_role(GTK_WINDOW(dialog
), "smiley_dialog");
711 gtk_window_set_position(GTK_WINDOW(dialog
), GTK_WIN_POS_MOUSE
);
713 if (unique_smileys
!= NULL
) {
714 struct smiley_button_list
*ls
, *it
, *it_tmp
;
717 int max_line_width
, num_lines
;
720 /* We use hboxes packed in a vbox */
722 line
= gtk_hbox_new(FALSE
, 0);
725 num_lines
= floor(sqrt(g_slist_length(unique_smileys
)));
726 smiley_table
= gtk_vbox_new(FALSE
, 0);
728 /* create list of smileys sorted by height */
729 while (unique_smileys
) {
730 GtkIMHtmlSmiley
*smiley
= unique_smileys
->data
;
731 if (!smiley
->hidden
) {
733 ls
= sort_smileys(ls
, toolbar
, &max_line_width
, smiley
->file
, smiley
->smile
);
735 unique_smileys
= unique_smileys
->next
;
737 /* pack buttons of the list */
738 max_line_width
= max_line_width
/ num_lines
;
743 gtk_box_pack_start(GTK_BOX(line
), it
->button
, FALSE
, FALSE
, 0);
744 gtk_widget_show(it
->button
);
745 line_width
+= it
->width
;
746 if (line_width
>= max_line_width
) {
747 gtk_box_pack_start(GTK_BOX(smiley_table
), line
, FALSE
, FALSE
, 0);
748 line
= gtk_hbox_new(FALSE
, 0);
756 gtk_box_pack_start(GTK_BOX(smiley_table
), line
, FALSE
, TRUE
, 0);
758 gtk_widget_add_events(dialog
, GDK_KEY_PRESS_MASK
);
761 smiley_table
= gtk_label_new(_("This theme has no available smileys."));
762 gtk_widget_add_events(dialog
, GDK_KEY_PRESS_MASK
| GDK_BUTTON_PRESS_MASK
);
763 g_signal_connect(G_OBJECT(dialog
), "button-press-event", (GCallback
)smiley_dialog_input_cb
, toolbar
);
766 g_signal_connect(G_OBJECT(dialog
), "key-press-event", (GCallback
)smiley_dialog_input_cb
, toolbar
);
767 gtk_container_add(GTK_CONTAINER(dialog
), smiley_table
);
769 gtk_widget_show(smiley_table
);
771 gtk_container_set_border_width(GTK_CONTAINER(dialog
), 5);
773 /* connect signals */
774 g_signal_connect(G_OBJECT(dialog
), "delete_event",
775 G_CALLBACK(close_smiley_dialog
), toolbar
);
777 /* show everything */
778 gtk_window_set_title(GTK_WINDOW(dialog
), _("Smile!"));
779 gtk_widget_show_all(dialog
);
781 winpidgin_ensure_onscreen(dialog
);
784 toolbar
->smiley_dialog
= dialog
;
786 gtk_widget_grab_focus(toolbar
->imhtml
);
789 static void update_buttons_cb(GtkIMHtml
*imhtml
, GtkIMHtmlButtons buttons
, GtkIMHtmlToolbar
*toolbar
)
791 gtk_widget_set_sensitive(GTK_WIDGET(toolbar
->bold
), buttons
& GTK_IMHTML_BOLD
);
792 gtk_widget_set_sensitive(GTK_WIDGET(toolbar
->italic
), buttons
& GTK_IMHTML_ITALIC
);
793 gtk_widget_set_sensitive(GTK_WIDGET(toolbar
->underline
), buttons
& GTK_IMHTML_UNDERLINE
);
794 gtk_widget_set_sensitive(GTK_WIDGET(toolbar
->strikethrough
), buttons
& GTK_IMHTML_STRIKE
);
796 gtk_widget_set_sensitive(GTK_WIDGET(toolbar
->larger_size
), buttons
& GTK_IMHTML_GROW
);
797 gtk_widget_set_sensitive(GTK_WIDGET(toolbar
->smaller_size
), buttons
& GTK_IMHTML_SHRINK
);
799 gtk_widget_set_sensitive(GTK_WIDGET(toolbar
->font
), buttons
& GTK_IMHTML_FACE
);
800 gtk_widget_set_sensitive(GTK_WIDGET(toolbar
->fgcolor
), buttons
& GTK_IMHTML_FORECOLOR
);
801 gtk_widget_set_sensitive(GTK_WIDGET(toolbar
->bgcolor
), buttons
& GTK_IMHTML_BACKCOLOR
);
803 gtk_widget_set_sensitive(GTK_WIDGET(toolbar
->clear
),
804 (buttons
& GTK_IMHTML_BOLD
||
805 buttons
& GTK_IMHTML_ITALIC
||
806 buttons
& GTK_IMHTML_UNDERLINE
||
807 buttons
& GTK_IMHTML_STRIKE
||
808 buttons
& GTK_IMHTML_GROW
||
809 buttons
& GTK_IMHTML_SHRINK
||
810 buttons
& GTK_IMHTML_FACE
||
811 buttons
& GTK_IMHTML_FORECOLOR
||
812 buttons
& GTK_IMHTML_BACKCOLOR
));
814 gtk_widget_set_sensitive(GTK_WIDGET(toolbar
->image
), buttons
& GTK_IMHTML_IMAGE
);
815 gtk_widget_set_sensitive(GTK_WIDGET(toolbar
->link
), buttons
& GTK_IMHTML_LINK
);
816 gtk_widget_set_sensitive(GTK_WIDGET(toolbar
->smiley
), buttons
& GTK_IMHTML_SMILEY
);
819 /* we call this when we want to _set_active the toggle button, it'll
820 * block the callback thats connected to the button so we don't have to
821 * do the double toggling hack
823 static void toggle_button_set_active_block(GtkToggleButton
*button
,
825 GtkIMHtmlToolbar
*toolbar
)
828 g_return_if_fail(toolbar
);
830 object
= g_object_ref(button
);
831 g_signal_handlers_block_matched(object
, G_SIGNAL_MATCH_DATA
,
832 0, 0, NULL
, NULL
, toolbar
);
833 gtk_toggle_button_set_active(button
, is_active
);
834 g_signal_handlers_unblock_matched(object
, G_SIGNAL_MATCH_DATA
,
835 0, 0, NULL
, NULL
, toolbar
);
836 g_object_unref(object
);
839 static void update_buttons(GtkIMHtmlToolbar
*toolbar
)
841 gboolean bold
, italic
, underline
, strike
;
844 GtkLabel
*label
= g_object_get_data(G_OBJECT(toolbar
), "font_label");
846 gtk_label_set_label(label
, _("_Font"));
848 gtk_imhtml_get_current_format(GTK_IMHTML(toolbar
->imhtml
),
849 &bold
, &italic
, &underline
);
850 strike
= GTK_IMHTML(toolbar
->imhtml
)->edit
.strike
;
852 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar
->bold
)) != bold
)
853 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar
->bold
), bold
,
855 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar
->italic
)) != italic
)
856 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar
->italic
), italic
,
858 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar
->underline
)) != underline
)
859 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar
->underline
),
861 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toolbar
->strikethrough
)) != strike
)
862 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar
->strikethrough
),
865 /* These buttons aren't ever "active". */
866 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar
->smaller_size
), FALSE
);
867 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar
->larger_size
), FALSE
);
870 gchar
*markup
= g_strdup_printf("<b>%s</b>",
871 gtk_label_get_label(label
));
872 gtk_label_set_markup_with_mnemonic(label
, markup
);
876 gchar
*markup
= g_strdup_printf("<i>%s</i>",
877 gtk_label_get_label(label
));
878 gtk_label_set_markup_with_mnemonic(label
, markup
);
882 gchar
*markup
= g_strdup_printf("<u>%s</u>",
883 gtk_label_get_label(label
));
884 gtk_label_set_markup_with_mnemonic(label
, markup
);
888 gchar
*markup
= g_strdup_printf("<s>%s</s>",
889 gtk_label_get_label(label
));
890 gtk_label_set_markup_with_mnemonic(label
, markup
);
894 tmp
= gtk_imhtml_get_current_fontface(GTK_IMHTML(toolbar
->imhtml
));
895 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar
->font
),
896 (tmp
!= NULL
), toolbar
);
898 gchar
*markup
= g_strdup_printf("<span font_desc=\"%s\">%s</span>",
899 tmp
, gtk_label_get_label(label
));
900 gtk_label_set_markup_with_mnemonic(label
, markup
);
905 tmp
= gtk_imhtml_get_current_forecolor(GTK_IMHTML(toolbar
->imhtml
));
906 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar
->fgcolor
),
907 (tmp
!= NULL
), toolbar
);
909 gchar
*markup
= g_strdup_printf("<span foreground=\"%s\">%s</span>",
910 tmp
, gtk_label_get_label(label
));
911 gtk_label_set_markup_with_mnemonic(label
, markup
);
916 tmp
= gtk_imhtml_get_current_backcolor(GTK_IMHTML(toolbar
->imhtml
));
917 tmp2
= gtk_imhtml_get_current_background(GTK_IMHTML(toolbar
->imhtml
));
918 toggle_button_set_active_block(GTK_TOGGLE_BUTTON(toolbar
->bgcolor
),
919 (tmp
!= NULL
|| tmp2
!= NULL
), toolbar
);
921 gchar
*markup
= g_strdup_printf("<span background=\"%s\">%s</span>",
922 tmp
, gtk_label_get_label(label
));
923 gtk_label_set_markup_with_mnemonic(label
, markup
);
930 static void toggle_button_cb(GtkIMHtml
*imhtml
, GtkIMHtmlButtons buttons
, GtkIMHtmlToolbar
*toolbar
)
932 update_buttons(toolbar
);
935 static void update_format_cb(GtkIMHtml
*imhtml
, GtkIMHtmlToolbar
*toolbar
) {
936 update_buttons(toolbar
);
939 static void mark_set_cb(GtkTextBuffer
*buffer
, GtkTextIter
*location
,
940 GtkTextMark
*mark
, GtkIMHtmlToolbar
*toolbar
)
942 if(mark
!= gtk_text_buffer_get_insert(buffer
))
945 update_buttons(toolbar
);
949 /* This comes from gtkmenutoolbutton.c from gtk+
950 * Copyright (C) 2003 Ricardo Fernandez Pascual
951 * Copyright (C) 2004 Paolo Borelli
954 menu_position_func (GtkMenu
*menu
,
960 GtkWidget
*widget
= GTK_WIDGET(data
);
961 GtkRequisition menu_req
;
962 gint ythickness
= widget
->style
->ythickness
;
965 gtk_widget_size_request(GTK_WIDGET (menu
), &menu_req
);
966 gdk_window_get_origin(widget
->window
, x
, y
);
967 *x
+= widget
->allocation
.x
;
968 *y
+= widget
->allocation
.y
+ widget
->allocation
.height
;
971 pidgin_menu_position_func_helper(menu
, x
, y
, push_in
, data
);
973 if (savy
> *y
+ ythickness
+ 1)
974 *y
-= widget
->allocation
.height
;
977 static void pidgin_menu_clicked(GtkWidget
*button
, GtkMenu
*menu
)
979 gtk_widget_show_all(GTK_WIDGET(menu
));
980 gtk_menu_popup(menu
, NULL
, NULL
, menu_position_func
, button
, 0, gtk_get_current_event_time());
983 static void pidgin_menu_deactivate(GtkWidget
*menu
, GtkToggleButton
*button
)
985 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button
), FALSE
);
991 /* static guint signals [LAST_SIGNAL] = { 0 }; */
994 gtk_imhtmltoolbar_finalize (GObject
*object
)
996 GtkIMHtmlToolbar
*toolbar
= GTK_IMHTMLTOOLBAR(object
);
999 if (toolbar
->image_dialog
!= NULL
)
1001 gtk_widget_destroy(toolbar
->image_dialog
);
1002 toolbar
->image_dialog
= NULL
;
1005 destroy_toolbar_font(NULL
, NULL
, toolbar
);
1006 destroy_smiley_dialog(toolbar
);
1007 destroy_toolbar_bgcolor(NULL
, NULL
, toolbar
);
1008 destroy_toolbar_fgcolor(NULL
, NULL
, toolbar
);
1009 close_link_dialog(toolbar
);
1010 if (toolbar
->imhtml
) {
1011 g_signal_handlers_disconnect_matched(toolbar
->imhtml
,
1012 G_SIGNAL_MATCH_DATA
, 0, 0, NULL
, NULL
,
1014 g_signal_handlers_disconnect_matched(GTK_IMHTML(toolbar
->imhtml
)->text_buffer
,
1015 G_SIGNAL_MATCH_DATA
, 0, 0, NULL
, NULL
,
1020 gtk_object_sink(GTK_OBJECT(toolbar
->tooltips
));
1022 menu
= g_object_get_data(object
, "font_menu");
1024 gtk_widget_destroy(menu
);
1025 menu
= g_object_get_data(object
, "insert_menu");
1027 gtk_widget_destroy(menu
);
1029 purple_prefs_disconnect_by_handle(object
);
1031 G_OBJECT_CLASS(parent_class
)->finalize (object
);
1035 switch_toolbar_view(GtkWidget
*item
, GtkIMHtmlToolbar
*toolbar
)
1037 purple_prefs_set_bool(PIDGIN_PREFS_ROOT
"/conversations/toolbar/wide",
1038 !purple_prefs_get_bool(PIDGIN_PREFS_ROOT
"/conversations/toolbar/wide"));
1042 gtk_imhtmltoolbar_popup_menu(GtkWidget
*widget
, GdkEventButton
*event
, GtkIMHtmlToolbar
*toolbar
)
1048 if (event
->button
!= 3)
1051 wide
= GTK_WIDGET_VISIBLE(toolbar
->bold
);
1053 menu
= gtk_menu_new();
1054 item
= gtk_menu_item_new_with_mnemonic(wide
? _("Group Items") : _("Ungroup Items"));
1055 g_signal_connect(G_OBJECT(item
), "activate", G_CALLBACK(switch_toolbar_view
), toolbar
);
1056 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), item
);
1057 gtk_widget_show(item
);
1059 gtk_menu_popup(GTK_MENU(menu
), NULL
, NULL
, pidgin_menu_position_func_helper
,
1060 widget
, event
->button
, event
->time
);
1064 /* Boring GTK+ stuff */
1065 static void gtk_imhtmltoolbar_class_init (GtkIMHtmlToolbarClass
*class)
1067 GtkObjectClass
*object_class
;
1068 GObjectClass
*gobject_class
;
1069 object_class
= (GtkObjectClass
*) class;
1070 gobject_class
= (GObjectClass
*) class;
1071 parent_class
= gtk_type_class(GTK_TYPE_HBOX
);
1072 gobject_class
->finalize
= gtk_imhtmltoolbar_finalize
;
1074 purple_prefs_add_none(PIDGIN_PREFS_ROOT
"/conversations/toolbar");
1075 purple_prefs_add_bool(PIDGIN_PREFS_ROOT
"/conversations/toolbar/wide", FALSE
);
1078 static void gtk_imhtmltoolbar_create_old_buttons(GtkIMHtmlToolbar
*toolbar
)
1086 const char *tooltip
;
1088 {GTK_STOCK_BOLD
, G_CALLBACK(do_bold
), &toolbar
->bold
, _("Bold")},
1089 {GTK_STOCK_ITALIC
, do_italic
, &toolbar
->italic
, _("Italic")},
1090 {GTK_STOCK_UNDERLINE
, do_underline
, &toolbar
->underline
, _("Underline")},
1091 {GTK_STOCK_STRIKETHROUGH
, do_strikethrough
, &toolbar
->strikethrough
, _("Strikethrough")},
1092 {"", NULL
, NULL
, NULL
},
1093 {PIDGIN_STOCK_TOOLBAR_TEXT_LARGER
, do_big
, &toolbar
->larger_size
, _("Increase Font Size")},
1094 {PIDGIN_STOCK_TOOLBAR_TEXT_SMALLER
, do_small
, &toolbar
->smaller_size
, _("Decrease Font Size")},
1095 {"", NULL
, NULL
, NULL
},
1096 {PIDGIN_STOCK_TOOLBAR_FONT_FACE
, toggle_font
, &toolbar
->font
, _("Font Face")},
1097 {PIDGIN_STOCK_TOOLBAR_FGCOLOR
, toggle_bg_color
, &toolbar
->bgcolor
, _("Background Color")},
1098 {PIDGIN_STOCK_TOOLBAR_BGCOLOR
, toggle_fg_color
, &toolbar
->fgcolor
, _("Foreground Color")},
1099 {"", NULL
, NULL
, NULL
},
1100 {PIDGIN_STOCK_CLEAR
, clear_formatting_cb
, &toolbar
->clear
, _("Reset Formatting")},
1101 {"", NULL
, NULL
, NULL
},
1102 {PIDGIN_STOCK_TOOLBAR_INSERT_LINK
, insert_link_cb
, &toolbar
->link
, _("Insert Link")},
1103 {PIDGIN_STOCK_TOOLBAR_INSERT_IMAGE
, insert_image_cb
, &toolbar
->image
, _("Insert IM Image")},
1104 {PIDGIN_STOCK_TOOLBAR_SMILEY
, insert_smiley_cb
, &toolbar
->smiley
, _("Insert Smiley")},
1105 {NULL
, NULL
, NULL
, NULL
}
1109 hbox
= gtk_hbox_new(FALSE
, 0);
1111 for (iter
= 0; buttons
[iter
].stock
; iter
++) {
1112 if (buttons
[iter
].stock
[0]) {
1113 button
= pidgin_pixbuf_toolbar_button_from_stock(buttons
[iter
].stock
);
1114 g_signal_connect(G_OBJECT(button
), "clicked",
1115 G_CALLBACK(buttons
[iter
].callback
), toolbar
);
1116 *(buttons
[iter
].button
) = button
;
1117 gtk_tooltips_set_tip(toolbar
->tooltips
, button
, buttons
[iter
].tooltip
, NULL
);
1119 button
= gtk_vseparator_new();
1120 gtk_box_pack_start(GTK_BOX(hbox
), button
, FALSE
, FALSE
, 0);
1123 gtk_box_pack_start(GTK_BOX(toolbar
), hbox
, FALSE
, FALSE
, 0);
1124 g_object_set_data(G_OBJECT(toolbar
), "wide-view", hbox
);
1128 button_sensitiveness_changed(GtkWidget
*button
, gpointer dontcare
, GtkWidget
*item
)
1130 gtk_widget_set_sensitive(item
, GTK_WIDGET_IS_SENSITIVE(button
));
1134 update_menuitem(GtkToggleButton
*button
, GtkCheckMenuItem
*item
)
1136 g_signal_handlers_block_by_func(G_OBJECT(item
), G_CALLBACK(gtk_button_clicked
), button
);
1137 gtk_check_menu_item_set_active(item
, gtk_toggle_button_get_active(button
));
1138 g_signal_handlers_unblock_by_func(G_OBJECT(item
), G_CALLBACK(gtk_button_clicked
), button
);
1142 enable_markup(GtkWidget
*widget
, gpointer null
)
1144 if (GTK_IS_LABEL(widget
))
1145 g_object_set(G_OBJECT(widget
), "use-markup", TRUE
, NULL
);
1149 imhtmltoolbar_view_pref_changed(const char *name
, PurplePrefType type
,
1150 gconstpointer value
, gpointer toolbar
)
1153 gtk_widget_hide_all(g_object_get_data(G_OBJECT(toolbar
), "lean-view"));
1154 gtk_widget_show_all(g_object_get_data(G_OBJECT(toolbar
), "wide-view"));
1156 gtk_widget_hide_all(g_object_get_data(G_OBJECT(toolbar
), "wide-view"));
1157 gtk_widget_show_all(g_object_get_data(G_OBJECT(toolbar
), "lean-view"));
1161 static void gtk_imhtmltoolbar_init (GtkIMHtmlToolbar
*toolbar
)
1163 GtkWidget
*hbox
= GTK_WIDGET(toolbar
), *event
= gtk_event_box_new();
1164 GtkWidget
*bbox
, *box
= gtk_hbox_new(FALSE
, 0);
1167 GtkWidget
*insert_button
;
1168 GtkWidget
*font_button
;
1169 GtkWidget
*font_menu
;
1170 GtkWidget
*insert_menu
;
1171 GtkWidget
*menuitem
;
1179 {_("<b>_Bold</b>"), &toolbar
->bold
, TRUE
},
1180 {_("<i>_Italic</i>"), &toolbar
->italic
, TRUE
},
1181 {_("<u>_Underline</u>"), &toolbar
->underline
, TRUE
},
1182 {_("<span strikethrough='true'>Strikethrough</span>"), &toolbar
->strikethrough
, TRUE
},
1183 {_("<span size='larger'>_Larger</span>"), &toolbar
->larger_size
, TRUE
},
1185 {_("_Normal"), &toolbar
->normal_size
, TRUE
},
1187 {_("<span size='smaller'>_Smaller</span>"), &toolbar
->smaller_size
, TRUE
},
1188 /* If we want to show the formatting for the following items, we would
1189 * need to update them when formatting changes. The above items don't need
1190 * no updating nor nothin' */
1191 {_("_Font face"), &toolbar
->font
, TRUE
},
1192 {_("Foreground _color"), &toolbar
->fgcolor
, TRUE
},
1193 {_("Bac_kground color"), &toolbar
->bgcolor
, TRUE
},
1194 {_("_Reset formatting"), &toolbar
->clear
, FALSE
},
1198 toolbar
->imhtml
= NULL
;
1199 toolbar
->font_dialog
= NULL
;
1200 toolbar
->fgcolor_dialog
= NULL
;
1201 toolbar
->bgcolor_dialog
= NULL
;
1202 toolbar
->link_dialog
= NULL
;
1203 toolbar
->smiley_dialog
= NULL
;
1204 toolbar
->image_dialog
= NULL
;
1206 toolbar
->tooltips
= gtk_tooltips_new();
1208 gtk_box_set_spacing(GTK_BOX(toolbar
), 3);
1210 gtk_imhtmltoolbar_create_old_buttons(toolbar
);
1213 font_button
= gtk_toggle_button_new();
1214 gtk_button_set_relief(GTK_BUTTON(font_button
), GTK_RELIEF_NONE
);
1215 bbox
= gtk_hbox_new(FALSE
, 3);
1216 gtk_container_add(GTK_CONTAINER(font_button
), bbox
);
1217 image
= gtk_image_new_from_stock(GTK_STOCK_BOLD
, gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL
));
1218 gtk_box_pack_start(GTK_BOX(bbox
), image
, FALSE
, FALSE
, 0);
1219 label
= gtk_label_new_with_mnemonic(_("_Font"));
1220 gtk_label_set_use_markup(GTK_LABEL(label
), TRUE
);
1221 g_object_set_data(G_OBJECT(hbox
), "font_label", label
);
1222 gtk_box_pack_start(GTK_BOX(bbox
), label
, FALSE
, FALSE
, 0);
1223 gtk_box_pack_start(GTK_BOX(box
), font_button
, FALSE
, FALSE
, 0);
1224 gtk_widget_show_all(font_button
);
1226 font_menu
= gtk_menu_new();
1227 g_object_set_data(G_OBJECT(toolbar
), "font_menu", font_menu
);
1229 for (i
= 0; buttons
[i
].label
; i
++) {
1230 GtkWidget
*old
= *buttons
[i
].button
;
1231 if (buttons
[i
].check
) {
1232 menuitem
= gtk_check_menu_item_new_with_mnemonic(buttons
[i
].label
);
1233 g_signal_connect_after(G_OBJECT(old
), "toggled",
1234 G_CALLBACK(update_menuitem
), menuitem
);
1236 menuitem
= gtk_menu_item_new_with_mnemonic(buttons
[i
].label
);
1238 g_signal_connect_swapped(G_OBJECT(menuitem
), "activate",
1239 G_CALLBACK(gtk_button_clicked
), old
);
1240 gtk_menu_shell_append(GTK_MENU_SHELL(font_menu
), menuitem
);
1241 g_signal_connect(G_OBJECT(old
), "notify::sensitive",
1242 G_CALLBACK(button_sensitiveness_changed
), menuitem
);
1243 gtk_container_foreach(GTK_CONTAINER(menuitem
), (GtkCallback
)enable_markup
, NULL
);
1246 g_signal_connect_swapped(G_OBJECT(font_button
), "button-press-event", G_CALLBACK(gtk_widget_activate
), font_button
);
1247 g_signal_connect(G_OBJECT(font_button
), "activate", G_CALLBACK(pidgin_menu_clicked
), font_menu
);
1248 g_signal_connect(G_OBJECT(font_menu
), "deactivate", G_CALLBACK(pidgin_menu_deactivate
), font_button
);
1251 sep
= gtk_vseparator_new();
1252 gtk_box_pack_start(GTK_BOX(box
), sep
, FALSE
, FALSE
, 0);
1253 gtk_widget_show_all(sep
);
1256 insert_button
= gtk_toggle_button_new();
1257 gtk_button_set_relief(GTK_BUTTON(insert_button
), GTK_RELIEF_NONE
);
1258 bbox
= gtk_hbox_new(FALSE
, 3);
1259 gtk_container_add(GTK_CONTAINER(insert_button
), bbox
);
1260 image
= gtk_image_new_from_stock(PIDGIN_STOCK_TOOLBAR_INSERT
, gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL
));
1261 gtk_box_pack_start(GTK_BOX(bbox
), image
, FALSE
, FALSE
, 0);
1262 label
= gtk_label_new_with_mnemonic(_("_Insert"));
1263 gtk_box_pack_start(GTK_BOX(bbox
), label
, FALSE
, FALSE
, 0);
1264 gtk_box_pack_start(GTK_BOX(box
), insert_button
, FALSE
, FALSE
, 0);
1265 gtk_widget_show_all(insert_button
);
1267 insert_menu
= gtk_menu_new();
1268 g_object_set_data(G_OBJECT(toolbar
), "insert_menu", insert_menu
);
1270 menuitem
= gtk_menu_item_new_with_mnemonic(_("_Smiley"));
1271 g_signal_connect_swapped(G_OBJECT(menuitem
), "activate", G_CALLBACK(gtk_button_clicked
), toolbar
->smiley
);
1272 gtk_menu_shell_append(GTK_MENU_SHELL(insert_menu
), menuitem
);
1273 g_signal_connect(G_OBJECT(toolbar
->smiley
), "notify::sensitive",
1274 G_CALLBACK(button_sensitiveness_changed
), menuitem
);
1276 menuitem
= gtk_menu_item_new_with_mnemonic(_("_Image"));
1277 g_signal_connect_swapped(G_OBJECT(menuitem
), "activate", G_CALLBACK(gtk_button_clicked
), toolbar
->image
);
1278 gtk_menu_shell_append(GTK_MENU_SHELL(insert_menu
), menuitem
);
1279 g_signal_connect(G_OBJECT(toolbar
->image
), "notify::sensitive",
1280 G_CALLBACK(button_sensitiveness_changed
), menuitem
);
1282 menuitem
= gtk_menu_item_new_with_mnemonic(_("_Link"));
1283 g_signal_connect_swapped(G_OBJECT(menuitem
), "activate", G_CALLBACK(gtk_button_clicked
), toolbar
->link
);
1284 gtk_menu_shell_append(GTK_MENU_SHELL(insert_menu
), menuitem
);
1285 g_signal_connect(G_OBJECT(toolbar
->link
), "notify::sensitive",
1286 G_CALLBACK(button_sensitiveness_changed
), menuitem
);
1288 menuitem
= gtk_menu_item_new_with_mnemonic(_("_Horizontal rule"));
1289 g_signal_connect(G_OBJECT(menuitem
), "activate" , G_CALLBACK(insert_hr_cb
), toolbar
);
1290 gtk_menu_shell_append(GTK_MENU_SHELL(insert_menu
), menuitem
);
1291 toolbar
->insert_hr
= menuitem
;
1293 g_signal_connect_swapped(G_OBJECT(insert_button
), "button-press-event", G_CALLBACK(gtk_widget_activate
), insert_button
);
1294 g_signal_connect(G_OBJECT(insert_button
), "activate", G_CALLBACK(pidgin_menu_clicked
), insert_menu
);
1295 g_signal_connect(G_OBJECT(insert_menu
), "deactivate", G_CALLBACK(pidgin_menu_deactivate
), insert_button
);
1296 toolbar
->sml
= NULL
;
1298 gtk_box_pack_start(GTK_BOX(hbox
), box
, FALSE
, FALSE
, 0);
1299 g_object_set_data(G_OBJECT(hbox
), "lean-view", box
);
1301 purple_prefs_connect_callback(toolbar
, PIDGIN_PREFS_ROOT
"/conversations/toolbar/wide",
1302 imhtmltoolbar_view_pref_changed
, toolbar
);
1303 purple_prefs_trigger_callback(PIDGIN_PREFS_ROOT
"/conversations/toolbar/wide");
1305 #if GTK_CHECK_VERSION(2,4,0)
1306 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event
), FALSE
);
1309 gtk_widget_add_events(event
, GDK_BUTTON_PRESS_MASK
);
1310 gtk_box_pack_start(GTK_BOX(hbox
), event
, TRUE
, TRUE
, 0);
1311 g_signal_connect(G_OBJECT(event
), "button-press-event", G_CALLBACK(gtk_imhtmltoolbar_popup_menu
), toolbar
);
1312 gtk_widget_show(event
);
1315 GtkWidget
*gtk_imhtmltoolbar_new()
1317 return GTK_WIDGET(g_object_new(gtk_imhtmltoolbar_get_type(), NULL
));
1320 GType
gtk_imhtmltoolbar_get_type()
1322 static GType imhtmltoolbar_type
= 0;
1324 if (!imhtmltoolbar_type
) {
1325 static const GTypeInfo imhtmltoolbar_info
= {
1326 sizeof(GtkIMHtmlToolbarClass
),
1329 (GClassInitFunc
) gtk_imhtmltoolbar_class_init
,
1332 sizeof (GtkIMHtmlToolbar
),
1334 (GInstanceInitFunc
) gtk_imhtmltoolbar_init
,
1338 imhtmltoolbar_type
= g_type_register_static(GTK_TYPE_HBOX
,
1339 "GtkIMHtmlToolbar", &imhtmltoolbar_info
, 0);
1342 return imhtmltoolbar_type
;
1346 void gtk_imhtmltoolbar_attach(GtkIMHtmlToolbar
*toolbar
, GtkWidget
*imhtml
)
1348 GtkIMHtmlButtons buttons
;
1349 gboolean bold
, italic
, underline
;
1351 g_return_if_fail(toolbar
!= NULL
);
1352 g_return_if_fail(GTK_IS_IMHTMLTOOLBAR(toolbar
));
1353 g_return_if_fail(imhtml
!= NULL
);
1354 g_return_if_fail(GTK_IS_IMHTML(imhtml
));
1356 toolbar
->imhtml
= imhtml
;
1357 g_signal_connect(G_OBJECT(imhtml
), "format_buttons_update", G_CALLBACK(update_buttons_cb
), toolbar
);
1358 g_signal_connect_after(G_OBJECT(imhtml
), "format_function_toggle", G_CALLBACK(toggle_button_cb
), toolbar
);
1359 g_signal_connect_after(G_OBJECT(imhtml
), "format_function_clear", G_CALLBACK(update_format_cb
), toolbar
);
1360 g_signal_connect(G_OBJECT(imhtml
), "format_function_update", G_CALLBACK(update_format_cb
), toolbar
);
1361 g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml
)->text_buffer
), "mark-set", G_CALLBACK(mark_set_cb
), toolbar
);
1363 buttons
= gtk_imhtml_get_format_functions(GTK_IMHTML(imhtml
));
1364 update_buttons_cb(GTK_IMHTML(imhtml
), buttons
, toolbar
);
1366 gtk_imhtml_get_current_format(GTK_IMHTML(imhtml
), &bold
, &italic
, &underline
);
1368 update_buttons(toolbar
);
1371 void gtk_imhtmltoolbar_associate_smileys(GtkIMHtmlToolbar
*toolbar
, const char *proto_id
)
1373 g_free(toolbar
->sml
);
1374 toolbar
->sml
= g_strdup(proto_id
);