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.
36 #include "gtkinfobar.h"
37 #include "gtkaccessible.h"
38 #include "gtkbuildable.h"
42 #include "gtkbutton.h"
44 #include "gtkbindings.h"
45 #include "gtkdialog.h"
47 #include "gtkprivate.h"
49 #include "gdkkeysyms.h"
55 * @short_description: Report important messages to the user
57 * @see_also: #GtkStatusbar, #GtkMessageDialog
59 * #GtkInfoBar is a widget that can be used to show messages to
60 * the user without showing a dialog. It is often temporarily shown
61 * at the top or bottom of a document. In contrast to #GtkDialog, which
62 * has a horizontal action area at the bottom, #GtkInfoBar has a
63 * vertical action area at the side.
65 * The API of #GtkInfoBar is very similar to #GtkDialog, allowing you
66 * to add buttons to the action area with gtk_info_bar_add_button() or
67 * gtk_info_bar_new_with_buttons(). The sensitivity of action widgets
68 * can be controlled with gtk_info_bar_set_response_sensitive().
69 * To add widgets to the main content area of a #GtkInfoBar, use
70 * gtk_info_bar_get_content_area() and add your widgets to the container.
72 * Similar to #GtkMessageDialog, the contents of a #GtkInfoBar can by
73 * classified as error message, warning, informational message, etc,
74 * by using gtk_info_bar_set_message_type(). GTK+ uses the message type
75 * to determine the background color of the message area.
78 * <title>Simple GtkInfoBar usage.</title>
80 * /* set up info bar */
81 * info_bar = gtk_info_bar_new ();
82 * gtk_widget_set_no_show_all (info_bar, TRUE);
83 * message_label = gtk_label_new ("");
84 * gtk_widget_show (message_label);
85 * content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
86 * gtk_container_add (GTK_CONTAINER (content_area), message_label);
87 * gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
88 * GTK_STOCK_OK, GTK_RESPONSE_OK);
89 * g_signal_connect (info_bar, "response",
90 * G_CALLBACK (gtk_widget_hide), NULL);
91 * gtk_table_attach (GTK_TABLE (table),
94 * GTK_EXPAND | GTK_FILL, 0,
99 * /* show an error message */
100 * gtk_label_set_text (GTK_LABEL (message_label), error_message);
101 * gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar),
102 * GTK_MESSAGE_ERROR);
103 * gtk_widget_show (info_bar);
107 * <refsect2 id="GtkInfoBar-BUILDER-UI">
108 * <title>GtkInfoBar as GtkBuildable</title>
110 * The GtkInfoBar implementation of the GtkBuildable interface exposes
111 * the content area and action area as internal children with the names
112 * "content_area" and "action_area".
115 * GtkInfoBar supports a custom <action-widgets> element, which
116 * can contain multiple <action-widget> elements. The "response"
117 * attribute specifies a numeric response, and the content of the element
118 * is the id of widget (which should be a child of the dialogs @action_area).
123 #define GTK_INFO_BAR_GET_PRIVATE(object) \
124 (G_TYPE_INSTANCE_GET_PRIVATE ((object), \
134 struct _GtkInfoBarPrivate
136 GtkWidget *content_area;
137 GtkWidget *action_area;
139 GtkMessageType message_type;
142 typedef struct _ResponseData ResponseData;
156 static guint signals[LAST_SIGNAL];
159 static void gtk_info_bar_set_property (GObject *object,
163 static void gtk_info_bar_get_property (GObject *object,
167 static void gtk_info_bar_style_set (GtkWidget *widget,
168 GtkStyle *prev_style);
169 static gboolean gtk_info_bar_expose (GtkWidget *widget,
170 GdkEventExpose *event);
171 static void gtk_info_bar_buildable_interface_init (GtkBuildableIface *iface);
172 static GObject *gtk_info_bar_buildable_get_internal_child (GtkBuildable *buildable,
174 const gchar *childname);
175 static gboolean gtk_info_bar_buildable_custom_tag_start (GtkBuildable *buildable,
178 const gchar *tagname,
179 GMarkupParser *parser,
181 static void gtk_info_bar_buildable_custom_finished (GtkBuildable *buildable,
184 const gchar *tagname,
188 G_DEFINE_TYPE_WITH_CODE (GtkInfoBar, gtk_info_bar, GTK_TYPE_HBOX,
189 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
190 gtk_info_bar_buildable_interface_init))
193 gtk_info_bar_set_property (GObject *object,
198 GtkInfoBar *info_bar;
199 GtkInfoBarPrivate *priv;
201 info_bar = GTK_INFO_BAR (object);
202 priv = GTK_INFO_BAR_GET_PRIVATE (info_bar);
206 case PROP_MESSAGE_TYPE:
207 gtk_info_bar_set_message_type (info_bar, g_value_get_enum (value));
210 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
216 gtk_info_bar_get_property (GObject *object,
221 GtkInfoBar *info_bar;
222 GtkInfoBarPrivate *priv;
224 info_bar = GTK_INFO_BAR (object);
225 priv = GTK_INFO_BAR_GET_PRIVATE (info_bar);
229 case PROP_MESSAGE_TYPE:
230 g_value_set_enum (value, gtk_info_bar_get_message_type (info_bar));
233 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
239 gtk_info_bar_finalize (GObject *object)
241 G_OBJECT_CLASS (gtk_info_bar_parent_class)->finalize (object);
245 response_data_free (gpointer data)
247 g_slice_free (ResponseData, data);
250 static ResponseData *
251 get_response_data (GtkWidget *widget,
254 ResponseData *ad = g_object_get_data (G_OBJECT (widget),
255 "gtk-info-bar-response-data");
257 if (ad == NULL && create)
259 ad = g_slice_new (ResponseData);
261 g_object_set_data_full (G_OBJECT (widget),
262 I_("gtk-info-bar-response-data"),
271 find_button (GtkInfoBar *info_bar,
274 GList *children, *list;
275 GtkWidget *child = NULL;
277 children = gtk_container_get_children (GTK_CONTAINER (info_bar->priv->action_area));
279 for (list = children; list; list = list->next)
281 ResponseData *rd = get_response_data (list->data, FALSE);
283 if (rd && rd->response_id == response_id)
290 g_list_free (children);
296 gtk_info_bar_close (GtkInfoBar *info_bar)
298 if (!find_button (info_bar, GTK_RESPONSE_CANCEL))
301 gtk_info_bar_response (GTK_INFO_BAR (info_bar),
302 GTK_RESPONSE_CANCEL);
306 gtk_info_bar_expose (GtkWidget *widget,
307 GdkEventExpose *event)
309 GtkInfoBarPrivate *priv = GTK_INFO_BAR_GET_PRIVATE (widget);
310 gboolean use_tooltip_style;
311 const char* type_detail[] = {
320 gtk_widget_style_get (widget,
321 "use-tooltip-style", &use_tooltip_style,
324 if (use_tooltip_style)
327 detail = type_detail[priv->message_type];
329 gtk_paint_flat_box (widget->style,
336 widget->allocation.x,
337 widget->allocation.y,
338 widget->allocation.width + 1,
339 widget->allocation.height + 1);
341 if (GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->expose_event)
342 GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->expose_event (widget, event);
348 gtk_info_bar_class_init (GtkInfoBarClass *klass)
350 GtkWidgetClass *widget_class;
351 GObjectClass *object_class;
352 GtkBindingSet *binding_set;
354 widget_class = GTK_WIDGET_CLASS (klass);
355 object_class = G_OBJECT_CLASS (klass);
357 object_class->get_property = gtk_info_bar_get_property;
358 object_class->set_property = gtk_info_bar_set_property;
359 object_class->finalize = gtk_info_bar_finalize;
361 widget_class->style_set = gtk_info_bar_style_set;
362 widget_class->expose_event = gtk_info_bar_expose;
364 klass->close = gtk_info_bar_close;
367 * GtkInfoBar:message-type:
369 * The type of the message.
371 * The type is used to determine the colors to use in the info bar.
372 * The following symbolic color names can by used to customize
374 * "info_fg_color", "info_bg_color",
375 * "warning_fg_color", "warning_bg_color",
376 * "question_fg_color", "question_bg_color",
377 * "error_fg_color", "error_bg_color",
378 * "other_fg_color", "other_bg_color".
382 g_object_class_install_property (object_class,
384 g_param_spec_enum ("message-type",
386 P_("The type of message"),
387 GTK_TYPE_MESSAGE_TYPE,
389 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
391 * GtkInfoBar::response:
392 * @info_bar: the object on which the signal is emitted
393 * @response_id: the response ID
395 * Emitted when an action widget is clicked or the application programmer
396 * calls gtk_dialog_response(). The @response_id depends on which action
397 * widget was clicked.
401 signals[RESPONSE] = g_signal_new (I_("response"),
402 G_OBJECT_CLASS_TYPE (klass),
404 G_STRUCT_OFFSET (GtkInfoBarClass, response),
406 g_cclosure_marshal_VOID__INT,
413 * The ::close signal is a
414 * <link linkend="keybinding-signals">keybinding signal</link>
415 * which gets emitted when the user uses a keybinding to dismiss
418 * The default binding for this signal is the Escape key.
422 signals[CLOSE] = g_signal_new (I_("close"),
423 G_OBJECT_CLASS_TYPE (klass),
424 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
425 G_STRUCT_OFFSET (GtkInfoBarClass, close),
427 g_cclosure_marshal_VOID__VOID,
431 * GtkInfoBar:content-area-border:
433 * The width of the border around the content
434 * content area of the info bar.
438 gtk_widget_class_install_style_property (widget_class,
439 g_param_spec_int ("content-area-border",
440 P_("Content area border"),
441 P_("Width of border around the content area"),
445 GTK_PARAM_READABLE));
448 * GtkInfoBar:content-area-spacing:
450 * The default spacing used between elements of the
451 * content area of the info bar.
455 gtk_widget_class_install_style_property (widget_class,
456 g_param_spec_int ("content-area-spacing",
457 P_("Content area spacing"),
458 P_("Spacing between elements of the area"),
462 GTK_PARAM_READABLE));
465 * GtkInfoBar:button-spacing:
467 * Spacing between buttons in the action area of the info bar.
471 gtk_widget_class_install_style_property (widget_class,
472 g_param_spec_int ("button-spacing",
473 P_("Button spacing"),
474 P_("Spacing between buttons"),
478 GTK_PARAM_READABLE));
481 * GtkInfoBar:action-area-border:
483 * Width of the border around the action area of the info bar.
487 gtk_widget_class_install_style_property (widget_class,
488 g_param_spec_int ("action-area-border",
489 P_("Action area border"),
490 P_("Width of border around the action area"),
494 GTK_PARAM_READABLE));
497 * GtkInfoBar:use-tooltip-style:
499 * When %TRUE, use the same background/foreground color as #GtkTooltip.
500 * Otherwise, GTK+ uses #GtkInfoBar::message-type to determine which
501 * symbolic colors to use.
505 gtk_widget_class_install_style_property (widget_class,
506 g_param_spec_boolean ("use-tooltip-style",
507 P_("Use tooltip style"),
508 P_("Wether to use the same style as GtkTooltip for drawing"),
510 GTK_PARAM_READABLE));
512 binding_set = gtk_binding_set_by_class (klass);
514 gtk_binding_entry_add_signal (binding_set, GDK_Escape, 0, "close", 0);
516 g_type_class_add_private (object_class, sizeof (GtkInfoBarPrivate));
520 gtk_info_bar_update_colors (GtkInfoBar *info_bar)
522 GtkWidget *widget = (GtkWidget*)info_bar;
523 GtkInfoBarPrivate *priv;
524 GdkColor default_border_color = { 0, 0xb800, 0xad00, 0x9d00 };
525 GdkColor default_fill_color = { 0, 0xff00, 0xff00, 0xbf00 };
527 GdkColor sym_fg, sym_bg;
528 gboolean use_tooltip_style;
530 const char* fg_color_name[] = {
537 const char* bg_color_name[] = {
546 priv = GTK_INFO_BAR_GET_PRIVATE (info_bar);
547 style = gtk_widget_get_style (widget);
549 gtk_widget_style_get (widget,
550 "use-tooltip-style", &use_tooltip_style, NULL);
554 if (gtk_style_lookup_color (style, fg_color_name[priv->message_type], &sym_fg) &&
555 gtk_style_lookup_color (style, bg_color_name[priv->message_type], &sym_bg))
561 else if (use_tooltip_style)
563 style = gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget),
564 "gtk-tooltip", "GtkTooltip", G_TYPE_NONE);
567 fg = &style->fg[GTK_STATE_NORMAL];
568 bg = &style->bg[GTK_STATE_NORMAL];
572 fg = &default_border_color;
573 bg = &default_fill_color;
581 if (!gdk_color_equal (bg, &widget->style->bg[GTK_STATE_NORMAL]))
582 gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, bg);
583 if (!gdk_color_equal (fg, &widget->style->fg[GTK_STATE_NORMAL]))
584 gtk_widget_modify_fg (widget, GTK_STATE_NORMAL, fg);
589 gtk_info_bar_style_set (GtkWidget *widget,
590 GtkStyle *prev_style)
592 GtkInfoBar *info_bar = GTK_INFO_BAR (widget);
594 gint action_area_border;
595 gint content_area_spacing;
596 gint content_area_border;
598 gtk_widget_style_get (widget,
599 "button-spacing", &button_spacing,
600 "action-area-border", &action_area_border,
601 "content-area-spacing", &content_area_spacing,
602 "content-area-border", &content_area_border,
605 gtk_box_set_spacing (GTK_BOX (info_bar->priv->action_area), button_spacing);
606 gtk_container_set_border_width (GTK_CONTAINER (info_bar->priv->action_area),
608 gtk_box_set_spacing (GTK_BOX (info_bar->priv->content_area), content_area_spacing);
609 gtk_container_set_border_width (GTK_CONTAINER (info_bar->priv->content_area),
610 content_area_border);
612 gtk_info_bar_update_colors (info_bar);
616 gtk_info_bar_init (GtkInfoBar *info_bar)
618 GtkWidget *content_area;
619 GtkWidget *action_area;
621 gtk_widget_push_composite_child ();
623 info_bar->priv = GTK_INFO_BAR_GET_PRIVATE (info_bar);
625 content_area = gtk_hbox_new (FALSE, 0);
626 gtk_widget_show (content_area);
627 gtk_box_pack_start (GTK_BOX (info_bar), content_area, TRUE, TRUE, 0);
629 action_area = gtk_vbutton_box_new ();
630 gtk_widget_show (action_area);
631 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
632 gtk_box_pack_start (GTK_BOX (info_bar), action_area, FALSE, TRUE, 0);
634 gtk_widget_set_app_paintable (GTK_WIDGET (info_bar), TRUE);
636 info_bar->priv->content_area = content_area;
637 info_bar->priv->action_area = action_area;
639 gtk_widget_pop_composite_child ();
642 static GtkBuildableIface *parent_buildable_iface;
645 gtk_info_bar_buildable_interface_init (GtkBuildableIface *iface)
647 parent_buildable_iface = g_type_interface_peek_parent (iface);
648 iface->get_internal_child = gtk_info_bar_buildable_get_internal_child;
649 iface->custom_tag_start = gtk_info_bar_buildable_custom_tag_start;
650 iface->custom_finished = gtk_info_bar_buildable_custom_finished;
654 gtk_info_bar_buildable_get_internal_child (GtkBuildable *buildable,
656 const gchar *childname)
658 if (strcmp (childname, "content_area") == 0)
659 return G_OBJECT (GTK_INFO_BAR (buildable)->priv->content_area);
660 else if (strcmp (childname, "action_area") == 0)
661 return G_OBJECT (GTK_INFO_BAR (buildable)->priv->action_area);
663 return parent_buildable_iface->get_internal_child (buildable,
669 get_response_for_widget (GtkInfoBar *info_bar,
674 rd = get_response_data (widget, FALSE);
676 return GTK_RESPONSE_NONE;
678 return rd->response_id;
682 action_widget_activated (GtkWidget *widget,
683 GtkInfoBar *info_bar)
687 response_id = get_response_for_widget (info_bar, widget);
688 gtk_info_bar_response (info_bar, response_id);
692 * gtk_info_bar_add_action_widget:
693 * @info_bar: a #GtkInfoBar
694 * @child: an activatable widget
695 * @response_id: response ID for @child
697 * Add an activatable widget to the action area of a #GtkInfoBar,
698 * connecting a signal handler that will emit the #GtkInfoBar::response
699 * signal on the message area when the widget is activated. The widget
700 * is appended to the end of the message areas action area.
705 gtk_info_bar_add_action_widget (GtkInfoBar *info_bar,
712 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
713 g_return_if_fail (GTK_IS_WIDGET (child));
715 ad = get_response_data (child, TRUE);
717 ad->response_id = response_id;
719 if (GTK_IS_BUTTON (child))
720 signal_id = g_signal_lookup ("clicked", GTK_TYPE_BUTTON);
722 signal_id = GTK_WIDGET_GET_CLASS (child)->activate_signal;
728 closure = g_cclosure_new_object (G_CALLBACK (action_widget_activated),
729 G_OBJECT (info_bar));
730 g_signal_connect_closure_by_id (child, signal_id, 0, closure, FALSE);
733 g_warning ("Only 'activatable' widgets can be packed into the action area of a GtkInfoBar");
735 gtk_box_pack_end (GTK_BOX (info_bar->priv->action_area),
736 child, FALSE, FALSE, 0);
737 if (response_id == GTK_RESPONSE_HELP)
738 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (info_bar->priv->action_area),
743 * gtk_info_bar_get_action_area:
744 * @info_bar: a #GtkInfoBar
746 * Returns the action area of @info_bar.
748 * Returns: the action area.
753 gtk_info_bar_get_action_area (GtkInfoBar *info_bar)
755 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
757 return info_bar->priv->action_area;
761 * gtk_info_bar_get_content_area:
762 * @info_bar: a #GtkInfoBar
764 * Returns the content area of @info_bar.
766 * Returns: the content area.
771 gtk_info_bar_get_content_area (GtkInfoBar *info_bar)
773 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
775 return info_bar->priv->content_area;
779 * gtk_info_bar_add_button:
780 * @info_bar: a #GtkInfoBar
781 * @button_text: text of button, or stock ID
782 * @response_id: response ID for the button
784 * Adds a button with the given text (or a stock button, if button_text
785 * is a stock ID) and sets things up so that clicking the button will emit
786 * the "response" signal with the given response_id. The button is appended
787 * to the end of the info bars's action area. The button widget is
788 * returned, but usually you don't need it.
790 * Returns: the button widget that was added
795 gtk_info_bar_add_button (GtkInfoBar *info_bar,
796 const gchar *button_text,
801 g_return_val_if_fail (GTK_IS_INFO_BAR (info_bar), NULL);
802 g_return_val_if_fail (button_text != NULL, NULL);
804 button = gtk_button_new_from_stock (button_text);
806 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
808 gtk_widget_show (button);
810 gtk_info_bar_add_action_widget (info_bar, button, response_id);
816 add_buttons_valist (GtkInfoBar *info_bar,
817 const gchar *first_button_text,
823 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
825 if (first_button_text == NULL)
828 text = first_button_text;
829 response_id = va_arg (args, gint);
833 gtk_info_bar_add_button (info_bar, text, response_id);
835 text = va_arg (args, gchar*);
839 response_id = va_arg (args, int);
844 * gtk_info_bar_add_buttons:
845 * @info_bar: a #GtkInfoBar
846 * @first_button_text: button text or stock ID
847 * @...: response ID for first button, then more text-response_id pairs,
850 * Adds more buttons, same as calling gtk_info_bar_add_button()
851 * repeatedly. The variable argument list should be %NULL-terminated
852 * as with gtk_info_bar_new_with_buttons(). Each button must have both
853 * text and response ID.
858 gtk_info_bar_add_buttons (GtkInfoBar *info_bar,
859 const gchar *first_button_text,
864 va_start (args, first_button_text);
865 add_buttons_valist (info_bar, first_button_text, args);
872 * Creates a new #GtkInfoBar object.
874 * Returns: a new #GtkInfoBar object
879 gtk_info_bar_new (void)
881 return g_object_new (GTK_TYPE_INFO_BAR, NULL);
885 * gtk_info_bar_new_with_buttons:
886 * @first_button_text: stock ID or text to go in first button, or %NULL
887 * @...: response ID for first button, then additional buttons, ending
890 * Creates a new #GtkInfoBar with buttons. Button text/response ID
891 * pairs should be listed, with a %NULL pointer ending the list.
892 * Button text can be either a stock ID such as %GTK_STOCK_OK, or
893 * some arbitrary text. A response ID can be any positive number,
894 * or one of the values in the #GtkResponseType enumeration. If the
895 * user clicks one of these dialog buttons, GtkInfoBar will emit
896 * the "response" signal with the corresponding response ID.
898 * Returns: a new #GtkInfoBar
901 gtk_info_bar_new_with_buttons (const gchar *first_button_text,
904 GtkInfoBar *info_bar;
907 info_bar = GTK_INFO_BAR (gtk_info_bar_new ());
909 va_start (args, first_button_text);
910 add_buttons_valist (info_bar, first_button_text, args);
913 return GTK_WIDGET (info_bar);
917 * gtk_info_bar_set_response_sensitive:
918 * @info_bar: a #GtkInfoBar
919 * @response_id: a response ID
920 * @setting: TRUE for sensitive
922 * Calls gtk_widget_set_sensitive (widget, setting) for each
923 * widget in the info bars's action area with the given response_id.
924 * A convenient way to sensitize/desensitize dialog buttons.
929 gtk_info_bar_set_response_sensitive (GtkInfoBar *info_bar,
933 GList *children, *list;
935 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
937 children = gtk_container_get_children (GTK_CONTAINER (info_bar->priv->action_area));
939 for (list = children; list; list = list->next)
941 GtkWidget *widget = list->data;
942 ResponseData *rd = get_response_data (widget, FALSE);
944 if (rd && rd->response_id == response_id)
945 gtk_widget_set_sensitive (widget, setting);
948 g_list_free (children);
952 * gtk_info_bar_set_default_response:
953 * @info_bar: a #GtkInfoBar
954 * @response_id: a response ID
956 * Sets the last widget in the info bar's action area with
957 * the given response_id as the default widget for the dialog.
958 * Pressing "Enter" normally activates the default widget.
963 gtk_info_bar_set_default_response (GtkInfoBar *info_bar,
966 GList *children, *list;
968 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
970 children = gtk_container_get_children (GTK_CONTAINER (info_bar->priv->action_area));
972 for (list = children; list; list = list->next)
974 GtkWidget *widget = list->data;
975 ResponseData *rd = get_response_data (widget, FALSE);
977 if (rd && rd->response_id == response_id)
978 gtk_widget_grab_default (widget);
981 g_list_free (children);
985 * gtk_info_bar_set_default_response:
986 * @info_bar: a #GtkInfoBar
987 * @response_id: a response ID
989 * Emits the 'response' signal with the given @response_id.
994 gtk_info_bar_response (GtkInfoBar *info_bar,
997 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
999 g_signal_emit (info_bar, signals[RESPONSE], 0, response_id);
1010 GtkInfoBar *info_bar;
1011 GtkBuilder *builder;
1014 } ActionWidgetsSubParserData;
1017 attributes_start_element (GMarkupParseContext *context,
1018 const gchar *element_name,
1019 const gchar **names,
1020 const gchar **values,
1024 ActionWidgetsSubParserData *parser_data = (ActionWidgetsSubParserData*)user_data;
1027 if (strcmp (element_name, "action-widget") == 0)
1029 for (i = 0; names[i]; i++)
1030 if (strcmp (names[i], "response") == 0)
1031 parser_data->response = g_strdup (values[i]);
1033 else if (strcmp (element_name, "action-widgets") == 0)
1036 g_warning ("Unsupported tag for GtkInfoBar: %s\n", element_name);
1040 attributes_text_element (GMarkupParseContext *context,
1046 ActionWidgetsSubParserData *parser_data = (ActionWidgetsSubParserData*)user_data;
1047 ActionWidgetInfo *item;
1049 if (!parser_data->response)
1052 item = g_new (ActionWidgetInfo, 1);
1053 item->widget_name = g_strndup (text, text_len);
1054 item->response_id = parser_data->response;
1055 parser_data->items = g_slist_prepend (parser_data->items, item);
1056 parser_data->response = NULL;
1059 static const GMarkupParser attributes_parser =
1061 attributes_start_element,
1063 attributes_text_element,
1067 gtk_info_bar_buildable_custom_tag_start (GtkBuildable *buildable,
1068 GtkBuilder *builder,
1070 const gchar *tagname,
1071 GMarkupParser *parser,
1074 ActionWidgetsSubParserData *parser_data;
1079 if (strcmp (tagname, "action-widgets") == 0)
1081 parser_data = g_slice_new0 (ActionWidgetsSubParserData);
1082 parser_data->info_bar = GTK_INFO_BAR (buildable);
1083 parser_data->items = NULL;
1085 *parser = attributes_parser;
1086 *data = parser_data;
1090 return parent_buildable_iface->custom_tag_start (buildable, builder, child,
1091 tagname, parser, data);
1095 gtk_info_bar_buildable_custom_finished (GtkBuildable *buildable,
1096 GtkBuilder *builder,
1098 const gchar *tagname,
1102 ActionWidgetsSubParserData *parser_data;
1104 GtkInfoBar *info_bar;
1108 if (strcmp (tagname, "action-widgets"))
1110 parent_buildable_iface->custom_finished (buildable, builder, child,
1111 tagname, user_data);
1115 info_bar = GTK_INFO_BAR (buildable);
1116 parser_data = (ActionWidgetsSubParserData*)user_data;
1117 parser_data->items = g_slist_reverse (parser_data->items);
1119 for (l = parser_data->items; l; l = l->next)
1121 ActionWidgetInfo *item = l->data;
1123 object = gtk_builder_get_object (builder, item->widget_name);
1126 g_warning ("Unknown object %s specified in action-widgets of %s",
1128 gtk_buildable_get_name (GTK_BUILDABLE (buildable)));
1132 ad = get_response_data (GTK_WIDGET (object), TRUE);
1133 ad->response_id = atoi (item->response_id);
1135 if (GTK_IS_BUTTON (object))
1136 signal_id = g_signal_lookup ("clicked", GTK_TYPE_BUTTON);
1138 signal_id = GTK_WIDGET_GET_CLASS (object)->activate_signal;
1144 closure = g_cclosure_new_object (G_CALLBACK (action_widget_activated),
1145 G_OBJECT (info_bar));
1146 g_signal_connect_closure_by_id (object,
1153 if (ad->response_id == GTK_RESPONSE_HELP)
1154 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (info_bar->priv->action_area),
1155 GTK_WIDGET (object), TRUE);
1157 g_free (item->widget_name);
1158 g_free (item->response_id);
1161 g_slist_free (parser_data->items);
1162 g_slice_free (ActionWidgetsSubParserData, parser_data);
1166 * gtk_info_bar_set_message_type:
1167 * @info_bar: a #GtkInfoBar
1168 * @message_type: a #GtkMessageType
1170 * Sets the message type of the message area.
1171 * GTK+ uses this type to determine what color to use
1172 * when drawing the message area.
1177 gtk_info_bar_set_message_type (GtkInfoBar *info_bar,
1178 GtkMessageType message_type)
1180 GtkInfoBarPrivate *priv;
1183 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
1185 priv = GTK_INFO_BAR_GET_PRIVATE (info_bar);
1187 if (priv->message_type != message_type)
1189 priv->message_type = message_type;
1191 gtk_info_bar_update_colors (info_bar);
1192 gtk_widget_queue_draw (GTK_WIDGET (info_bar));
1194 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (info_bar));
1195 if (GTK_IS_ACCESSIBLE (atk_obj))
1198 const char *stock_id = NULL;
1200 atk_object_set_role (atk_obj, ATK_ROLE_ALERT);
1202 switch (message_type)
1204 case GTK_MESSAGE_INFO:
1205 stock_id = GTK_STOCK_DIALOG_INFO;
1208 case GTK_MESSAGE_QUESTION:
1209 stock_id = GTK_STOCK_DIALOG_QUESTION;
1212 case GTK_MESSAGE_WARNING:
1213 stock_id = GTK_STOCK_DIALOG_WARNING;
1216 case GTK_MESSAGE_ERROR:
1217 stock_id = GTK_STOCK_DIALOG_ERROR;
1220 case GTK_MESSAGE_OTHER:
1224 g_warning ("Unknown GtkMessageType %u", message_type);
1230 gtk_stock_lookup (stock_id, &item);
1231 atk_object_set_name (atk_obj, item.label);
1235 g_object_notify (G_OBJECT (info_bar), "message-type");
1240 * gtk_info_bar_get_message_type:
1241 * @info_bar: a #GtkInfoBar
1243 * Returns the message type of the message area.
1245 * Returns: the message type of the message area.
1250 gtk_info_bar_get_message_type (GtkInfoBar *info_bar)
1252 GtkInfoBarPrivate *priv;
1254 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
1256 priv = GTK_INFO_BAR_GET_PRIVATE (info_bar);
1258 return priv->message_type;
1262 #define __GTK_INFO_BAR_C__
1263 #include "gtkaliasdef.c"