3 * This file is part of GTK+
5 * Copyright (C) 2005 - Paolo Maggi
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 * Modified by the gedit Team, 2005. See the AUTHORS file for a
25 * list of people on the gtk Team.
26 * See the gedit ChangeLog files for a list of changes.
28 * Modified by the GTK+ team, 2008-2009.
37 #include "evinfobar.h"
39 #include <gdk/gdkkeysyms.h>
43 * @short_description: Report important messages to the user
45 * @see_also: #GtkStatusbar, #GtkMessageDialog
47 * #GtkInfoBar is a widget that can be used to show messages to
48 * the user without showing a dialog. It is often temporarily shown
49 * at the top or bottom of a document. In contrast to #GtkDialog, which
50 * has a horizontal action area at the bottom, #GtkInfoBar has a
51 * vertical action area at the side.
53 * The API of #GtkInfoBar is very similar to #GtkDialog, allowing you
54 * to add buttons to the action area with gtk_info_bar_add_button() or
55 * gtk_info_bar_new_with_buttons(). The sensitivity of action widgets
56 * can be controlled with gtk_info_bar_set_response_sensitive().
57 * To add widgets to the main content area of a #GtkInfoBar, use
58 * gtk_info_bar_get_content_area() and add your widgets to the container.
60 * Similar to #GtkMessageDialog, the contents of a #GtkInfoBar can by
61 * classified as error message, warning, informational message, etc,
62 * by using gtk_info_bar_set_message_type(). GTK+ uses the message type
63 * to determine the background color of the message area.
66 * <title>Simple GtkInfoBar usage.</title>
68 * /* set up info bar */
69 * info_bar = gtk_info_bar_new ();
70 * gtk_widget_set_no_show_all (info_bar, TRUE);
71 * message_label = gtk_label_new ("");
72 * gtk_widget_show (message_label);
73 * content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
74 * gtk_container_add (GTK_CONTAINER (content_area), message_label);
75 * gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
76 * GTK_STOCK_OK, GTK_RESPONSE_OK);
77 * g_signal_connect (info_bar, "response",
78 * G_CALLBACK (gtk_widget_hide), NULL);
79 * gtk_table_attach (GTK_TABLE (table),
82 * GTK_EXPAND | GTK_FILL, 0,
87 * /* show an error message */
88 * gtk_label_set_text (GTK_LABEL (message_label), error_message);
89 * gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar),
91 * gtk_widget_show (info_bar);
95 * <refsect2 id="GtkInfoBar-BUILDER-UI">
96 * <title>GtkInfoBar as GtkBuildable</title>
98 * The GtkInfoBar implementation of the GtkBuildable interface exposes
99 * the content area and action area as internal children with the names
100 * "content_area" and "action_area".
103 * GtkInfoBar supports a custom <action-widgets> element, which
104 * can contain multiple <action-widget> elements. The "response"
105 * attribute specifies a numeric response, and the content of the element
106 * is the id of widget (which should be a child of the dialogs @action_area).
111 #define GTK_INFO_BAR_GET_PRIVATE(object) \
112 (G_TYPE_INSTANCE_GET_PRIVATE ((object), \
122 struct _EvInfoBarPrivate
124 GtkWidget *content_area;
125 GtkWidget *action_area;
127 GtkMessageType message_type;
130 typedef struct _ResponseData ResponseData;
144 static guint signals[LAST_SIGNAL];
147 static void gtk_info_bar_set_property (GObject *object,
151 static void gtk_info_bar_get_property (GObject *object,
155 static void gtk_info_bar_style_set (GtkWidget *widget,
156 GtkStyle *prev_style);
157 static gboolean gtk_info_bar_expose (GtkWidget *widget,
158 GdkEventExpose *event);
159 static void gtk_info_bar_buildable_interface_init (GtkBuildableIface *iface);
160 static GObject *gtk_info_bar_buildable_get_internal_child (GtkBuildable *buildable,
162 const gchar *childname);
163 static gboolean gtk_info_bar_buildable_custom_tag_start (GtkBuildable *buildable,
166 const gchar *tagname,
167 GMarkupParser *parser,
169 static void gtk_info_bar_buildable_custom_finished (GtkBuildable *buildable,
172 const gchar *tagname,
176 G_DEFINE_TYPE_WITH_CODE (EvInfoBar, ev_info_bar, GTK_TYPE_HBOX,
177 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
178 gtk_info_bar_buildable_interface_init))
181 gtk_info_bar_set_property (GObject *object,
187 EvInfoBarPrivate *priv;
189 info_bar = EV_INFO_BAR (object);
190 priv = GTK_INFO_BAR_GET_PRIVATE (info_bar);
194 case PROP_MESSAGE_TYPE:
195 ev_info_bar_set_message_type (info_bar, g_value_get_enum (value));
198 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
204 gtk_info_bar_get_property (GObject *object,
210 EvInfoBarPrivate *priv;
212 info_bar = EV_INFO_BAR (object);
213 priv = GTK_INFO_BAR_GET_PRIVATE (info_bar);
217 case PROP_MESSAGE_TYPE:
218 g_value_set_enum (value, ev_info_bar_get_message_type (info_bar));
221 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
227 gtk_info_bar_finalize (GObject *object)
229 G_OBJECT_CLASS (ev_info_bar_parent_class)->finalize (object);
233 response_data_free (gpointer data)
235 g_slice_free (ResponseData, data);
238 static ResponseData *
239 get_response_data (GtkWidget *widget,
242 ResponseData *ad = g_object_get_data (G_OBJECT (widget),
243 "gtk-info-bar-response-data");
245 if (ad == NULL && create)
247 ad = g_slice_new (ResponseData);
249 g_object_set_data_full (G_OBJECT (widget),
250 "gtk-info-bar-response-data",
259 find_button (EvInfoBar *info_bar,
262 GList *children, *list;
263 GtkWidget *child = NULL;
265 children = gtk_container_get_children (GTK_CONTAINER (info_bar->priv->action_area));
267 for (list = children; list; list = list->next)
269 ResponseData *rd = get_response_data (list->data, FALSE);
271 if (rd && rd->response_id == response_id)
278 g_list_free (children);
284 gtk_info_bar_close (EvInfoBar *info_bar)
286 if (!find_button (info_bar, GTK_RESPONSE_CANCEL))
289 ev_info_bar_response (EV_INFO_BAR (info_bar),
290 GTK_RESPONSE_CANCEL);
294 gtk_info_bar_expose (GtkWidget *widget,
295 GdkEventExpose *event)
297 EvInfoBarPrivate *priv = GTK_INFO_BAR_GET_PRIVATE (widget);
298 const char* type_detail[] = {
306 if (priv->message_type != GTK_MESSAGE_OTHER)
310 detail = type_detail[priv->message_type];
312 gtk_paint_box (widget->style,
319 widget->allocation.x,
320 widget->allocation.y,
321 widget->allocation.width,
322 widget->allocation.height);
325 if (GTK_WIDGET_CLASS (ev_info_bar_parent_class)->expose_event)
326 GTK_WIDGET_CLASS (ev_info_bar_parent_class)->expose_event (widget, event);
332 ev_info_bar_class_init (EvInfoBarClass *klass)
334 GtkWidgetClass *widget_class;
335 GObjectClass *object_class;
336 GtkBindingSet *binding_set;
338 widget_class = GTK_WIDGET_CLASS (klass);
339 object_class = G_OBJECT_CLASS (klass);
341 object_class->get_property = gtk_info_bar_get_property;
342 object_class->set_property = gtk_info_bar_set_property;
343 object_class->finalize = gtk_info_bar_finalize;
345 widget_class->style_set = gtk_info_bar_style_set;
346 widget_class->expose_event = gtk_info_bar_expose;
348 klass->close = gtk_info_bar_close;
351 * GtkInfoBar:message-type:
353 * The type of the message.
355 * The type is used to determine the colors to use in the info bar.
356 * The following symbolic color names can by used to customize
358 * "info_fg_color", "info_bg_color",
359 * "warning_fg_color", "warning_bg_color",
360 * "question_fg_color", "question_bg_color",
361 * "error_fg_color", "error_bg_color".
362 * "other_fg_color", "other_bg_color".
364 * If the type is #GTK_MESSAGE_OTHER, no info bar is painted but the
365 * colors are still set.
369 g_object_class_install_property (object_class,
371 g_param_spec_enum ("message-type",
373 "The type of message",
374 GTK_TYPE_MESSAGE_TYPE,
376 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
378 * GtkInfoBar::response:
379 * @info_bar: the object on which the signal is emitted
380 * @response_id: the response ID
382 * Emitted when an action widget is clicked or the application programmer
383 * calls gtk_dialog_response(). The @response_id depends on which action
384 * widget was clicked.
388 signals[RESPONSE] = g_signal_new ("response",
389 G_OBJECT_CLASS_TYPE (klass),
391 G_STRUCT_OFFSET (EvInfoBarClass, response),
393 g_cclosure_marshal_VOID__INT,
400 * The ::close signal is a
401 * <link linkend="keybinding-signals">keybinding signal</link>
402 * which gets emitted when the user uses a keybinding to dismiss
405 * The default binding for this signal is the Escape key.
409 signals[CLOSE] = g_signal_new ("close",
410 G_OBJECT_CLASS_TYPE (klass),
411 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
412 G_STRUCT_OFFSET (EvInfoBarClass, close),
414 g_cclosure_marshal_VOID__VOID,
418 * GtkInfoBar:content-area-border:
420 * The width of the border around the content
421 * content area of the info bar.
425 gtk_widget_class_install_style_property (widget_class,
426 g_param_spec_int ("content-area-border",
427 "Content area border",
428 "Width of border around the content area",
435 * GtkInfoBar:content-area-spacing:
437 * The default spacing used between elements of the
438 * content area of the info bar.
442 gtk_widget_class_install_style_property (widget_class,
443 g_param_spec_int ("content-area-spacing",
444 "Content area spacing",
445 "Spacing between elements of the area",
452 * GtkInfoBar:button-spacing:
454 * Spacing between buttons in the action area of the info bar.
458 gtk_widget_class_install_style_property (widget_class,
459 g_param_spec_int ("button-spacing",
461 "Spacing between buttons",
468 * GtkInfoBar:action-area-border:
470 * Width of the border around the action area of the info bar.
474 gtk_widget_class_install_style_property (widget_class,
475 g_param_spec_int ("action-area-border",
476 "Action area border",
477 "Width of border around the action area",
483 binding_set = gtk_binding_set_by_class (klass);
485 gtk_binding_entry_add_signal (binding_set, GDK_Escape, 0, "close", 0);
487 g_type_class_add_private (object_class, sizeof (EvInfoBarPrivate));
491 gtk_info_bar_update_colors (EvInfoBar *info_bar)
493 GtkWidget *widget = (GtkWidget*)info_bar;
494 EvInfoBarPrivate *priv;
495 GdkColor info_default_border_color = { 0, 0xb800, 0xad00, 0x9d00 };
496 GdkColor info_default_fill_color = { 0, 0xff00, 0xff00, 0xbf00 };
497 GdkColor warning_default_border_color = { 0, 0xb000, 0x7a00, 0x2b00 };
498 GdkColor warning_default_fill_color = { 0, 0xfc00, 0xaf00, 0x3e00 };
499 GdkColor question_default_border_color = { 0, 0x6200, 0x7b00, 0xd960 };
500 GdkColor question_default_fill_color = { 0, 0x8c00, 0xb000, 0xd700 };
501 GdkColor error_default_border_color = { 0, 0xa800, 0x2700, 0x2700 };
502 GdkColor error_default_fill_color = { 0, 0xf000, 0x3800, 0x3800 };
503 GdkColor other_default_border_color = { 0, 0xb800, 0xad00, 0x9d00 };
504 GdkColor other_default_fill_color = { 0, 0xff00, 0xff00, 0xbf00 };
506 GdkColor sym_fg, sym_bg;
508 const char* fg_color_name[] = {
515 const char* bg_color_name[] = {
523 priv = GTK_INFO_BAR_GET_PRIVATE (info_bar);
524 style = gtk_widget_get_style (widget);
526 if (gtk_style_lookup_color (style, fg_color_name[priv->message_type], &sym_fg) &&
527 gtk_style_lookup_color (style, bg_color_name[priv->message_type], &sym_bg))
534 switch (priv->message_type)
536 case GTK_MESSAGE_INFO:
537 fg = &info_default_border_color;
538 bg = &info_default_fill_color;
541 case GTK_MESSAGE_WARNING:
542 fg = &warning_default_border_color;
543 bg = &warning_default_fill_color;
546 case GTK_MESSAGE_QUESTION:
547 fg = &question_default_border_color;
548 bg = &question_default_fill_color;
551 case GTK_MESSAGE_ERROR:
552 fg = &error_default_border_color;
553 bg = &error_default_fill_color;
556 case GTK_MESSAGE_OTHER:
557 fg = &other_default_border_color;
558 bg = &other_default_fill_color;
563 if (!gdk_color_equal (bg, &widget->style->bg[GTK_STATE_NORMAL]))
564 gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, bg);
565 if (!gdk_color_equal (fg, &widget->style->fg[GTK_STATE_NORMAL]))
566 gtk_widget_modify_fg (widget, GTK_STATE_NORMAL, fg);
570 gtk_info_bar_style_set (GtkWidget *widget,
571 GtkStyle *prev_style)
573 EvInfoBar *info_bar = EV_INFO_BAR (widget);
575 gint action_area_border;
576 gint content_area_spacing;
577 gint content_area_border;
579 gtk_widget_style_get (widget,
580 "button-spacing", &button_spacing,
581 "action-area-border", &action_area_border,
582 "content-area-spacing", &content_area_spacing,
583 "content-area-border", &content_area_border,
586 gtk_box_set_spacing (GTK_BOX (info_bar->priv->action_area), button_spacing);
587 gtk_container_set_border_width (GTK_CONTAINER (info_bar->priv->action_area),
589 gtk_box_set_spacing (GTK_BOX (info_bar->priv->content_area), content_area_spacing);
590 gtk_container_set_border_width (GTK_CONTAINER (info_bar->priv->content_area),
591 content_area_border);
593 gtk_info_bar_update_colors (info_bar);
597 ev_info_bar_init (EvInfoBar *info_bar)
599 GtkWidget *content_area;
600 GtkWidget *action_area;
602 gtk_widget_push_composite_child ();
604 info_bar->priv = GTK_INFO_BAR_GET_PRIVATE (info_bar);
606 content_area = gtk_hbox_new (FALSE, 0);
607 gtk_widget_show (content_area);
608 gtk_box_pack_start (GTK_BOX (info_bar), content_area, TRUE, TRUE, 0);
610 action_area = gtk_vbutton_box_new ();
611 gtk_widget_show (action_area);
612 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
613 gtk_box_pack_start (GTK_BOX (info_bar), action_area, FALSE, TRUE, 0);
615 gtk_widget_set_app_paintable (GTK_WIDGET (info_bar), TRUE);
616 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (info_bar), TRUE);
618 info_bar->priv->content_area = content_area;
619 info_bar->priv->action_area = action_area;
621 gtk_widget_pop_composite_child ();
624 static GtkBuildableIface *parent_buildable_iface;
627 gtk_info_bar_buildable_interface_init (GtkBuildableIface *iface)
629 parent_buildable_iface = g_type_interface_peek_parent (iface);
630 iface->get_internal_child = gtk_info_bar_buildable_get_internal_child;
631 iface->custom_tag_start = gtk_info_bar_buildable_custom_tag_start;
632 iface->custom_finished = gtk_info_bar_buildable_custom_finished;
636 gtk_info_bar_buildable_get_internal_child (GtkBuildable *buildable,
638 const gchar *childname)
640 if (strcmp (childname, "content_area") == 0)
641 return G_OBJECT (EV_INFO_BAR (buildable)->priv->content_area);
642 else if (strcmp (childname, "action_area") == 0)
643 return G_OBJECT (EV_INFO_BAR (buildable)->priv->action_area);
645 return parent_buildable_iface->get_internal_child (buildable,
651 get_response_for_widget (EvInfoBar *info_bar,
656 rd = get_response_data (widget, FALSE);
658 return GTK_RESPONSE_NONE;
660 return rd->response_id;
664 action_widget_activated (GtkWidget *widget,
669 response_id = get_response_for_widget (info_bar, widget);
670 ev_info_bar_response (info_bar, response_id);
674 * gtk_info_bar_add_action_widget:
675 * @info_bar: a #GtkInfoBar
676 * @child: an activatable widget
677 * @response_id: response ID for @child
679 * Add an activatable widget to the action area of a #GtkInfoBar,
680 * connecting a signal handler that will emit the #GtkInfoBar::response
681 * signal on the message area when the widget is activated. The widget
682 * is appended to the end of the message areas action area.
687 ev_info_bar_add_action_widget (EvInfoBar *info_bar,
694 g_return_if_fail (EV_IS_INFO_BAR (info_bar));
695 g_return_if_fail (GTK_IS_WIDGET (child));
697 ad = get_response_data (child, TRUE);
699 ad->response_id = response_id;
701 if (GTK_IS_BUTTON (child))
702 signal_id = g_signal_lookup ("clicked", GTK_TYPE_BUTTON);
704 signal_id = GTK_WIDGET_GET_CLASS (child)->activate_signal;
710 closure = g_cclosure_new_object (G_CALLBACK (action_widget_activated),
711 G_OBJECT (info_bar));
712 g_signal_connect_closure_by_id (child, signal_id, 0, closure, FALSE);
715 g_warning ("Only 'activatable' widgets can be packed into the action area of a GtkInfoBar");
717 gtk_box_pack_end (GTK_BOX (info_bar->priv->action_area),
718 child, FALSE, FALSE, 0);
719 if (response_id == GTK_RESPONSE_HELP)
720 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (info_bar->priv->action_area),
725 * gtk_info_bar_get_action_area:
726 * @info_bar: a #GtkInfoBar
728 * Returns the action area of @info_bar.
730 * Returns: the action area.
735 ev_info_bar_get_action_area (EvInfoBar *info_bar)
737 g_return_val_if_fail (EV_IS_INFO_BAR (info_bar), NULL);
739 return info_bar->priv->action_area;
743 * gtk_info_bar_get_content_area:
744 * @info_bar: a #GtkInfoBar
746 * Returns the content area of @info_bar.
748 * Returns: the content area.
753 ev_info_bar_get_content_area (EvInfoBar *info_bar)
755 g_return_val_if_fail (EV_IS_INFO_BAR (info_bar), NULL);
757 return info_bar->priv->content_area;
761 * gtk_info_bar_add_button:
762 * @info_bar: a #GtkInfoBar
763 * @button_text: text of button, or stock ID
764 * @response_id: response ID for the button
766 * Adds a button with the given text (or a stock button, if button_text
767 * is a stock ID) and sets things up so that clicking the button will emit
768 * the "response" signal with the given response_id. The button is appended
769 * to the end of the info bars's action area. The button widget is
770 * returned, but usually you don't need it.
772 * Returns: the button widget that was added
777 ev_info_bar_add_button (EvInfoBar *info_bar,
778 const gchar *button_text,
783 g_return_val_if_fail (EV_IS_INFO_BAR (info_bar), NULL);
784 g_return_val_if_fail (button_text != NULL, NULL);
786 button = gtk_button_new_from_stock (button_text);
788 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
790 gtk_widget_show (button);
792 ev_info_bar_add_action_widget (info_bar, button, response_id);
798 add_buttons_valist (EvInfoBar *info_bar,
799 const gchar *first_button_text,
805 g_return_if_fail (EV_IS_INFO_BAR (info_bar));
807 if (first_button_text == NULL)
810 text = first_button_text;
811 response_id = va_arg (args, gint);
815 ev_info_bar_add_button (info_bar, text, response_id);
817 text = va_arg (args, gchar*);
821 response_id = va_arg (args, int);
826 * gtk_info_bar_add_buttons:
827 * @info_bar: a #GtkInfoBar
828 * @first_button_text: button text or stock ID
829 * @...: response ID for first button, then more text-response_id pairs,
832 * Adds more buttons, same as calling gtk_info_bar_add_button()
833 * repeatedly. The variable argument list should be %NULL-terminated
834 * as with gtk_info_bar_new_with_buttons(). Each button must have both
835 * text and response ID.
840 ev_info_bar_add_buttons (EvInfoBar *info_bar,
841 const gchar *first_button_text,
846 va_start (args, first_button_text);
847 add_buttons_valist (info_bar, first_button_text, args);
854 * Creates a new #GtkInfoBar object.
856 * Returns: a new #GtkInfoBar object
861 ev_info_bar_new (void)
863 return g_object_new (EV_TYPE_INFO_BAR, NULL);
867 * gtk_info_bar_new_with_buttons:
868 * @first_button_text: stock ID or text to go in first button, or %NULL
869 * @...: response ID for first button, then additional buttons, ending
872 * Creates a new #GtkInfoBar with buttons. Button text/response ID
873 * pairs should be listed, with a %NULL pointer ending the list.
874 * Button text can be either a stock ID such as %GTK_STOCK_OK, or
875 * some arbitrary text. A response ID can be any positive number,
876 * or one of the values in the #GtkResponseType enumeration. If the
877 * user clicks one of these dialog buttons, GtkInfoBar will emit
878 * the "response" signal with the corresponding response ID.
880 * Returns: a new #GtkInfoBar
883 ev_info_bar_new_with_buttons (const gchar *first_button_text,
889 info_bar = EV_INFO_BAR (ev_info_bar_new ());
891 va_start (args, first_button_text);
892 add_buttons_valist (info_bar, first_button_text, args);
895 return GTK_WIDGET (info_bar);
899 * gtk_info_bar_set_response_sensitive:
900 * @info_bar: a #GtkInfoBar
901 * @response_id: a response ID
902 * @setting: TRUE for sensitive
904 * Calls gtk_widget_set_sensitive (widget, setting) for each
905 * widget in the info bars's action area with the given response_id.
906 * A convenient way to sensitize/desensitize dialog buttons.
911 ev_info_bar_set_response_sensitive (EvInfoBar *info_bar,
915 GList *children, *list;
917 g_return_if_fail (EV_IS_INFO_BAR (info_bar));
919 children = gtk_container_get_children (GTK_CONTAINER (info_bar->priv->action_area));
921 for (list = children; list; list = list->next)
923 GtkWidget *widget = list->data;
924 ResponseData *rd = get_response_data (widget, FALSE);
926 if (rd && rd->response_id == response_id)
927 gtk_widget_set_sensitive (widget, setting);
930 g_list_free (children);
934 * gtk_info_bar_set_default_response:
935 * @info_bar: a #GtkInfoBar
936 * @response_id: a response ID
938 * Sets the last widget in the info bar's action area with
939 * the given response_id as the default widget for the dialog.
940 * Pressing "Enter" normally activates the default widget.
945 ev_info_bar_set_default_response (EvInfoBar *info_bar,
948 GList *children, *list;
950 g_return_if_fail (EV_IS_INFO_BAR (info_bar));
952 children = gtk_container_get_children (GTK_CONTAINER (info_bar->priv->action_area));
954 for (list = children; list; list = list->next)
956 GtkWidget *widget = list->data;
957 ResponseData *rd = get_response_data (widget, FALSE);
959 if (rd && rd->response_id == response_id)
960 gtk_widget_grab_default (widget);
963 g_list_free (children);
967 * gtk_info_bar_response:
968 * @info_bar: a #GtkInfoBar
969 * @response_id: a response ID
971 * Emits the 'response' signal with the given @response_id.
976 ev_info_bar_response (EvInfoBar *info_bar,
979 g_return_if_fail (EV_IS_INFO_BAR (info_bar));
981 g_signal_emit (info_bar, signals[RESPONSE], 0, response_id);
996 } ActionWidgetsSubParserData;
999 attributes_start_element (GMarkupParseContext *context,
1000 const gchar *element_name,
1001 const gchar **names,
1002 const gchar **values,
1006 ActionWidgetsSubParserData *parser_data = (ActionWidgetsSubParserData*)user_data;
1009 if (strcmp (element_name, "action-widget") == 0)
1011 for (i = 0; names[i]; i++)
1012 if (strcmp (names[i], "response") == 0)
1013 parser_data->response = g_strdup (values[i]);
1015 else if (strcmp (element_name, "action-widgets") == 0)
1018 g_warning ("Unsupported tag for GtkInfoBar: %s\n", element_name);
1022 attributes_text_element (GMarkupParseContext *context,
1028 ActionWidgetsSubParserData *parser_data = (ActionWidgetsSubParserData*)user_data;
1029 ActionWidgetInfo *item;
1031 if (!parser_data->response)
1034 item = g_new (ActionWidgetInfo, 1);
1035 item->widget_name = g_strndup (text, text_len);
1036 item->response_id = parser_data->response;
1037 parser_data->items = g_slist_prepend (parser_data->items, item);
1038 parser_data->response = NULL;
1041 static const GMarkupParser attributes_parser =
1043 attributes_start_element,
1045 attributes_text_element,
1049 gtk_info_bar_buildable_custom_tag_start (GtkBuildable *buildable,
1050 GtkBuilder *builder,
1052 const gchar *tagname,
1053 GMarkupParser *parser,
1056 ActionWidgetsSubParserData *parser_data;
1061 if (strcmp (tagname, "action-widgets") == 0)
1063 parser_data = g_slice_new0 (ActionWidgetsSubParserData);
1064 parser_data->info_bar = EV_INFO_BAR (buildable);
1065 parser_data->items = NULL;
1067 *parser = attributes_parser;
1068 *data = parser_data;
1072 return parent_buildable_iface->custom_tag_start (buildable, builder, child,
1073 tagname, parser, data);
1077 gtk_info_bar_buildable_custom_finished (GtkBuildable *buildable,
1078 GtkBuilder *builder,
1080 const gchar *tagname,
1084 ActionWidgetsSubParserData *parser_data;
1086 EvInfoBar *info_bar;
1090 if (strcmp (tagname, "action-widgets"))
1092 parent_buildable_iface->custom_finished (buildable, builder, child,
1093 tagname, user_data);
1097 info_bar = EV_INFO_BAR (buildable);
1098 parser_data = (ActionWidgetsSubParserData*)user_data;
1099 parser_data->items = g_slist_reverse (parser_data->items);
1101 for (l = parser_data->items; l; l = l->next)
1103 ActionWidgetInfo *item = l->data;
1105 object = gtk_builder_get_object (builder, item->widget_name);
1108 g_warning ("Unknown object %s specified in action-widgets of %s",
1110 gtk_buildable_get_name (GTK_BUILDABLE (buildable)));
1114 ad = get_response_data (GTK_WIDGET (object), TRUE);
1115 ad->response_id = atoi (item->response_id);
1117 if (GTK_IS_BUTTON (object))
1118 signal_id = g_signal_lookup ("clicked", GTK_TYPE_BUTTON);
1120 signal_id = GTK_WIDGET_GET_CLASS (object)->activate_signal;
1126 closure = g_cclosure_new_object (G_CALLBACK (action_widget_activated),
1127 G_OBJECT (info_bar));
1128 g_signal_connect_closure_by_id (object,
1135 if (ad->response_id == GTK_RESPONSE_HELP)
1136 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (info_bar->priv->action_area),
1137 GTK_WIDGET (object), TRUE);
1139 g_free (item->widget_name);
1140 g_free (item->response_id);
1143 g_slist_free (parser_data->items);
1144 g_slice_free (ActionWidgetsSubParserData, parser_data);
1148 * gtk_info_bar_set_message_type:
1149 * @info_bar: a #GtkInfoBar
1150 * @message_type: a #GtkMessageType
1152 * Sets the message type of the message area.
1153 * GTK+ uses this type to determine what color to use
1154 * when drawing the message area.
1159 ev_info_bar_set_message_type (EvInfoBar *info_bar,
1160 GtkMessageType message_type)
1162 EvInfoBarPrivate *priv;
1165 g_return_if_fail (EV_IS_INFO_BAR (info_bar));
1167 priv = GTK_INFO_BAR_GET_PRIVATE (info_bar);
1169 if (priv->message_type != message_type)
1171 priv->message_type = message_type;
1173 gtk_info_bar_update_colors (info_bar);
1174 gtk_widget_queue_draw (GTK_WIDGET (info_bar));
1176 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (info_bar));
1177 if (GTK_IS_ACCESSIBLE (atk_obj))
1180 const char *stock_id = NULL;
1182 atk_object_set_role (atk_obj, ATK_ROLE_ALERT);
1184 switch (message_type)
1186 case GTK_MESSAGE_INFO:
1187 stock_id = GTK_STOCK_DIALOG_INFO;
1190 case GTK_MESSAGE_QUESTION:
1191 stock_id = GTK_STOCK_DIALOG_QUESTION;
1194 case GTK_MESSAGE_WARNING:
1195 stock_id = GTK_STOCK_DIALOG_WARNING;
1198 case GTK_MESSAGE_ERROR:
1199 stock_id = GTK_STOCK_DIALOG_ERROR;
1202 case GTK_MESSAGE_OTHER:
1206 g_warning ("Unknown GtkMessageType %u", message_type);
1212 gtk_stock_lookup (stock_id, &item);
1213 atk_object_set_name (atk_obj, item.label);
1217 g_object_notify (G_OBJECT (info_bar), "message-type");
1222 * gtk_info_bar_get_message_type:
1223 * @info_bar: a #GtkInfoBar
1225 * Returns the message type of the message area.
1227 * Returns: the message type of the message area.
1232 ev_info_bar_get_message_type (EvInfoBar *info_bar)
1234 EvInfoBarPrivate *priv;
1236 g_return_val_if_fail (EV_IS_INFO_BAR (info_bar), GTK_MESSAGE_OTHER);
1238 priv = GTK_INFO_BAR_GET_PRIVATE (info_bar);
1240 return priv->message_type;
1244 #define __GTK_INFO_BAR_C__