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 "gtkorientable.h"
50 #include "gtktypebuiltins.h"
54 * @short_description: Report important messages to the user
56 * @see_also: #GtkStatusbar, #GtkMessageDialog
58 * #GtkInfoBar is a widget that can be used to show messages to
59 * the user without showing a dialog. It is often temporarily shown
60 * at the top or bottom of a document. In contrast to #GtkDialog, which
61 * has a horizontal action area at the bottom, #GtkInfoBar has a
62 * vertical action area at the side.
64 * The API of #GtkInfoBar is very similar to #GtkDialog, allowing you
65 * to add buttons to the action area with gtk_info_bar_add_button() or
66 * gtk_info_bar_new_with_buttons(). The sensitivity of action widgets
67 * can be controlled with gtk_info_bar_set_response_sensitive().
68 * To add widgets to the main content area of a #GtkInfoBar, use
69 * gtk_info_bar_get_content_area() and add your widgets to the container.
71 * Similar to #GtkMessageDialog, the contents of a #GtkInfoBar can by
72 * classified as error message, warning, informational message, etc,
73 * by using gtk_info_bar_set_message_type(). GTK+ uses the message type
74 * to determine the background color of the message area.
77 * <title>Simple GtkInfoBar usage.</title>
79 * /* set up info bar */
80 * info_bar = gtk_info_bar_new ();
81 * gtk_widget_set_no_show_all (info_bar, TRUE);
82 * message_label = gtk_label_new ("");
83 * gtk_widget_show (message_label);
84 * content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
85 * gtk_container_add (GTK_CONTAINER (content_area), message_label);
86 * gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
87 * GTK_STOCK_OK, GTK_RESPONSE_OK);
88 * g_signal_connect (info_bar, "response",
89 * G_CALLBACK (gtk_widget_hide), NULL);
90 * gtk_table_attach (GTK_TABLE (table),
93 * GTK_EXPAND | GTK_FILL, 0,
98 * /* show an error message */
99 * gtk_label_set_text (GTK_LABEL (message_label), error_message);
100 * gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar),
101 * GTK_MESSAGE_ERROR);
102 * gtk_widget_show (info_bar);
106 * <refsect2 id="GtkInfoBar-BUILDER-UI">
107 * <title>GtkInfoBar as GtkBuildable</title>
109 * The GtkInfoBar implementation of the GtkBuildable interface exposes
110 * the content area and action area as internal children with the names
111 * "content_area" and "action_area".
114 * GtkInfoBar supports a custom <action-widgets> element, which
115 * can contain multiple <action-widget> elements. The "response"
116 * attribute specifies a numeric response, and the content of the element
117 * is the id of widget (which should be a child of the dialogs @action_area).
128 struct _GtkInfoBarPrivate
130 GtkWidget *content_area;
131 GtkWidget *action_area;
133 GtkMessageType message_type;
136 typedef struct _ResponseData ResponseData;
150 static guint signals[LAST_SIGNAL];
153 static void gtk_info_bar_set_property (GObject *object,
157 static void gtk_info_bar_get_property (GObject *object,
161 static void gtk_info_bar_style_updated (GtkWidget *widget);
162 static gboolean gtk_info_bar_draw (GtkWidget *widget,
164 static void gtk_info_bar_buildable_interface_init (GtkBuildableIface *iface);
165 static GObject *gtk_info_bar_buildable_get_internal_child (GtkBuildable *buildable,
167 const gchar *childname);
168 static gboolean gtk_info_bar_buildable_custom_tag_start (GtkBuildable *buildable,
171 const gchar *tagname,
172 GMarkupParser *parser,
174 static void gtk_info_bar_buildable_custom_finished (GtkBuildable *buildable,
177 const gchar *tagname,
181 G_DEFINE_TYPE_WITH_CODE (GtkInfoBar, gtk_info_bar, GTK_TYPE_BOX,
182 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
183 gtk_info_bar_buildable_interface_init))
186 gtk_info_bar_set_property (GObject *object,
191 GtkInfoBar *info_bar = GTK_INFO_BAR (object);
195 case PROP_MESSAGE_TYPE:
196 gtk_info_bar_set_message_type (info_bar, g_value_get_enum (value));
199 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
205 gtk_info_bar_get_property (GObject *object,
210 GtkInfoBar *info_bar = GTK_INFO_BAR (object);
214 case PROP_MESSAGE_TYPE:
215 g_value_set_enum (value, gtk_info_bar_get_message_type (info_bar));
218 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
224 gtk_info_bar_finalize (GObject *object)
226 G_OBJECT_CLASS (gtk_info_bar_parent_class)->finalize (object);
230 response_data_free (gpointer data)
232 g_slice_free (ResponseData, data);
235 static ResponseData *
236 get_response_data (GtkWidget *widget,
239 ResponseData *ad = g_object_get_data (G_OBJECT (widget),
240 "gtk-info-bar-response-data");
242 if (ad == NULL && create)
244 ad = g_slice_new (ResponseData);
246 g_object_set_data_full (G_OBJECT (widget),
247 I_("gtk-info-bar-response-data"),
256 find_button (GtkInfoBar *info_bar,
259 GList *children, *list;
260 GtkWidget *child = NULL;
262 children = gtk_container_get_children (GTK_CONTAINER (info_bar->priv->action_area));
264 for (list = children; list; list = list->next)
266 ResponseData *rd = get_response_data (list->data, FALSE);
268 if (rd && rd->response_id == response_id)
275 g_list_free (children);
281 gtk_info_bar_close (GtkInfoBar *info_bar)
283 if (!find_button (info_bar, GTK_RESPONSE_CANCEL))
286 gtk_info_bar_response (GTK_INFO_BAR (info_bar),
287 GTK_RESPONSE_CANCEL);
291 gtk_info_bar_draw (GtkWidget *widget,
294 GtkInfoBarPrivate *priv = GTK_INFO_BAR (widget)->priv;
295 const char* type_class[] = {
296 GTK_STYLE_CLASS_INFO,
297 GTK_STYLE_CLASS_WARNING,
298 GTK_STYLE_CLASS_QUESTION,
299 GTK_STYLE_CLASS_ERROR,
303 if (priv->message_type != GTK_MESSAGE_OTHER)
305 GtkStyleContext *context;
307 context = gtk_widget_get_style_context (widget);
309 gtk_style_context_save (context);
311 if (type_class[priv->message_type])
312 gtk_style_context_add_class (context,
313 type_class[priv->message_type]);
315 gtk_render_background (context, cr, 0, 0,
316 gtk_widget_get_allocated_width (widget),
317 gtk_widget_get_allocated_height (widget));
318 gtk_render_frame (context, cr, 0, 0,
319 gtk_widget_get_allocated_width (widget),
320 gtk_widget_get_allocated_height (widget));
322 gtk_style_context_restore (context);
325 if (GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->draw)
326 GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->draw (widget, cr);
332 gtk_info_bar_class_init (GtkInfoBarClass *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_updated = gtk_info_bar_style_updated;
346 widget_class->draw = gtk_info_bar_draw;
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 P_("The type of message"),
374 GTK_TYPE_MESSAGE_TYPE,
376 GTK_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 (I_("response"),
389 G_OBJECT_CLASS_TYPE (klass),
391 G_STRUCT_OFFSET (GtkInfoBarClass, 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 (I_("close"),
410 G_OBJECT_CLASS_TYPE (klass),
411 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
412 G_STRUCT_OFFSET (GtkInfoBarClass, 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 P_("Content area border"),
428 P_("Width of border around the content area"),
432 GTK_PARAM_READABLE));
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 P_("Content area spacing"),
445 P_("Spacing between elements of the area"),
449 GTK_PARAM_READABLE));
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",
460 P_("Button spacing"),
461 P_("Spacing between buttons"),
465 GTK_PARAM_READABLE));
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 P_("Action area border"),
477 P_("Width of border around the action area"),
481 GTK_PARAM_READABLE));
483 binding_set = gtk_binding_set_by_class (klass);
485 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "close", 0);
487 g_type_class_add_private (object_class, sizeof (GtkInfoBarPrivate));
491 gtk_info_bar_style_updated (GtkWidget *widget)
493 GtkInfoBar *info_bar = GTK_INFO_BAR (widget);
495 gint action_area_border;
496 gint content_area_spacing;
497 gint content_area_border;
499 GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->style_updated (widget);
501 gtk_widget_style_get (widget,
502 "button-spacing", &button_spacing,
503 "action-area-border", &action_area_border,
504 "content-area-spacing", &content_area_spacing,
505 "content-area-border", &content_area_border,
508 gtk_box_set_spacing (GTK_BOX (info_bar->priv->action_area), button_spacing);
509 gtk_container_set_border_width (GTK_CONTAINER (info_bar->priv->action_area),
511 gtk_box_set_spacing (GTK_BOX (info_bar->priv->content_area), content_area_spacing);
512 gtk_container_set_border_width (GTK_CONTAINER (info_bar->priv->content_area),
513 content_area_border);
517 gtk_info_bar_init (GtkInfoBar *info_bar)
519 GtkWidget *content_area;
520 GtkWidget *action_area;
522 gtk_widget_push_composite_child ();
524 info_bar->priv = G_TYPE_INSTANCE_GET_PRIVATE (info_bar,
528 content_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
529 gtk_widget_show (content_area);
530 gtk_box_pack_start (GTK_BOX (info_bar), content_area, TRUE, TRUE, 0);
532 action_area = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);
533 gtk_widget_show (action_area);
534 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
535 gtk_box_pack_start (GTK_BOX (info_bar), action_area, FALSE, TRUE, 0);
537 gtk_widget_set_app_paintable (GTK_WIDGET (info_bar), TRUE);
538 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (info_bar), TRUE);
540 info_bar->priv->content_area = content_area;
541 info_bar->priv->action_area = action_area;
543 gtk_widget_pop_composite_child ();
546 static GtkBuildableIface *parent_buildable_iface;
549 gtk_info_bar_buildable_interface_init (GtkBuildableIface *iface)
551 parent_buildable_iface = g_type_interface_peek_parent (iface);
552 iface->get_internal_child = gtk_info_bar_buildable_get_internal_child;
553 iface->custom_tag_start = gtk_info_bar_buildable_custom_tag_start;
554 iface->custom_finished = gtk_info_bar_buildable_custom_finished;
558 gtk_info_bar_buildable_get_internal_child (GtkBuildable *buildable,
560 const gchar *childname)
562 if (strcmp (childname, "content_area") == 0)
563 return G_OBJECT (GTK_INFO_BAR (buildable)->priv->content_area);
564 else if (strcmp (childname, "action_area") == 0)
565 return G_OBJECT (GTK_INFO_BAR (buildable)->priv->action_area);
567 return parent_buildable_iface->get_internal_child (buildable,
573 get_response_for_widget (GtkInfoBar *info_bar,
578 rd = get_response_data (widget, FALSE);
580 return GTK_RESPONSE_NONE;
582 return rd->response_id;
586 action_widget_activated (GtkWidget *widget,
587 GtkInfoBar *info_bar)
591 response_id = get_response_for_widget (info_bar, widget);
592 gtk_info_bar_response (info_bar, response_id);
596 * gtk_info_bar_add_action_widget:
597 * @info_bar: a #GtkInfoBar
598 * @child: an activatable widget
599 * @response_id: response ID for @child
601 * Add an activatable widget to the action area of a #GtkInfoBar,
602 * connecting a signal handler that will emit the #GtkInfoBar::response
603 * signal on the message area when the widget is activated. The widget
604 * is appended to the end of the message areas action area.
609 gtk_info_bar_add_action_widget (GtkInfoBar *info_bar,
616 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
617 g_return_if_fail (GTK_IS_WIDGET (child));
619 ad = get_response_data (child, TRUE);
621 ad->response_id = response_id;
623 if (GTK_IS_BUTTON (child))
624 signal_id = g_signal_lookup ("clicked", GTK_TYPE_BUTTON);
626 signal_id = GTK_WIDGET_GET_CLASS (child)->activate_signal;
632 closure = g_cclosure_new_object (G_CALLBACK (action_widget_activated),
633 G_OBJECT (info_bar));
634 g_signal_connect_closure_by_id (child, signal_id, 0, closure, FALSE);
637 g_warning ("Only 'activatable' widgets can be packed into the action area of a GtkInfoBar");
639 gtk_box_pack_end (GTK_BOX (info_bar->priv->action_area),
640 child, FALSE, FALSE, 0);
641 if (response_id == GTK_RESPONSE_HELP)
642 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (info_bar->priv->action_area),
647 * gtk_info_bar_get_action_area:
648 * @info_bar: a #GtkInfoBar
650 * Returns the action area of @info_bar.
652 * Returns: (transfer none): the action area
657 gtk_info_bar_get_action_area (GtkInfoBar *info_bar)
659 g_return_val_if_fail (GTK_IS_INFO_BAR (info_bar), NULL);
661 return info_bar->priv->action_area;
665 * gtk_info_bar_get_content_area:
666 * @info_bar: a #GtkInfoBar
668 * Returns the content area of @info_bar.
670 * Returns: (transfer none): the content area
675 gtk_info_bar_get_content_area (GtkInfoBar *info_bar)
677 g_return_val_if_fail (GTK_IS_INFO_BAR (info_bar), NULL);
679 return info_bar->priv->content_area;
683 * gtk_info_bar_add_button:
684 * @info_bar: a #GtkInfoBar
685 * @button_text: text of button, or stock ID
686 * @response_id: response ID for the button
688 * Adds a button with the given text (or a stock button, if button_text
689 * is a stock ID) and sets things up so that clicking the button will emit
690 * the "response" signal with the given response_id. The button is appended
691 * to the end of the info bars's action area. The button widget is
692 * returned, but usually you don't need it.
694 * Returns: (transfer none): the #GtkButton widget that was added
699 gtk_info_bar_add_button (GtkInfoBar *info_bar,
700 const gchar *button_text,
705 g_return_val_if_fail (GTK_IS_INFO_BAR (info_bar), NULL);
706 g_return_val_if_fail (button_text != NULL, NULL);
708 button = gtk_button_new_from_stock (button_text);
710 gtk_widget_set_can_default (button, TRUE);
712 gtk_widget_show (button);
714 gtk_info_bar_add_action_widget (info_bar, button, response_id);
720 add_buttons_valist (GtkInfoBar *info_bar,
721 const gchar *first_button_text,
727 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
729 if (first_button_text == NULL)
732 text = first_button_text;
733 response_id = va_arg (args, gint);
737 gtk_info_bar_add_button (info_bar, text, response_id);
739 text = va_arg (args, gchar*);
743 response_id = va_arg (args, int);
748 * gtk_info_bar_add_buttons:
749 * @info_bar: a #GtkInfoBar
750 * @first_button_text: button text or stock ID
751 * @...: response ID for first button, then more text-response_id pairs,
754 * Adds more buttons, same as calling gtk_info_bar_add_button()
755 * repeatedly. The variable argument list should be %NULL-terminated
756 * as with gtk_info_bar_new_with_buttons(). Each button must have both
757 * text and response ID.
762 gtk_info_bar_add_buttons (GtkInfoBar *info_bar,
763 const gchar *first_button_text,
768 va_start (args, first_button_text);
769 add_buttons_valist (info_bar, first_button_text, args);
776 * Creates a new #GtkInfoBar object.
778 * Returns: a new #GtkInfoBar object
783 gtk_info_bar_new (void)
785 return g_object_new (GTK_TYPE_INFO_BAR, NULL);
789 * gtk_info_bar_new_with_buttons:
790 * @first_button_text: (allow-none): stock ID or text to go in first button, or %NULL
791 * @...: response ID for first button, then additional buttons, ending
794 * Creates a new #GtkInfoBar with buttons. Button text/response ID
795 * pairs should be listed, with a %NULL pointer ending the list.
796 * Button text can be either a stock ID such as %GTK_STOCK_OK, or
797 * some arbitrary text. A response ID can be any positive number,
798 * or one of the values in the #GtkResponseType enumeration. If the
799 * user clicks one of these dialog buttons, GtkInfoBar will emit
800 * the "response" signal with the corresponding response ID.
802 * Returns: a new #GtkInfoBar
805 gtk_info_bar_new_with_buttons (const gchar *first_button_text,
808 GtkInfoBar *info_bar;
811 info_bar = GTK_INFO_BAR (gtk_info_bar_new ());
813 va_start (args, first_button_text);
814 add_buttons_valist (info_bar, first_button_text, args);
817 return GTK_WIDGET (info_bar);
821 * gtk_info_bar_set_response_sensitive:
822 * @info_bar: a #GtkInfoBar
823 * @response_id: a response ID
824 * @setting: TRUE for sensitive
826 * Calls gtk_widget_set_sensitive (widget, setting) for each
827 * widget in the info bars's action area with the given response_id.
828 * A convenient way to sensitize/desensitize dialog buttons.
833 gtk_info_bar_set_response_sensitive (GtkInfoBar *info_bar,
837 GList *children, *list;
839 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
841 children = gtk_container_get_children (GTK_CONTAINER (info_bar->priv->action_area));
843 for (list = children; list; list = list->next)
845 GtkWidget *widget = list->data;
846 ResponseData *rd = get_response_data (widget, FALSE);
848 if (rd && rd->response_id == response_id)
849 gtk_widget_set_sensitive (widget, setting);
852 g_list_free (children);
856 * gtk_info_bar_set_default_response:
857 * @info_bar: a #GtkInfoBar
858 * @response_id: a response ID
860 * Sets the last widget in the info bar's action area with
861 * the given response_id as the default widget for the dialog.
862 * Pressing "Enter" normally activates the default widget.
864 * Note that this function currently requires @info_bar to
865 * be added to a widget hierarchy.
870 gtk_info_bar_set_default_response (GtkInfoBar *info_bar,
873 GList *children, *list;
875 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
877 children = gtk_container_get_children (GTK_CONTAINER (info_bar->priv->action_area));
879 for (list = children; list; list = list->next)
881 GtkWidget *widget = list->data;
882 ResponseData *rd = get_response_data (widget, FALSE);
884 if (rd && rd->response_id == response_id)
885 gtk_widget_grab_default (widget);
888 g_list_free (children);
892 * gtk_info_bar_response:
893 * @info_bar: a #GtkInfoBar
894 * @response_id: a response ID
896 * Emits the 'response' signal with the given @response_id.
901 gtk_info_bar_response (GtkInfoBar *info_bar,
904 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
906 g_signal_emit (info_bar, signals[RESPONSE], 0, response_id);
917 GtkInfoBar *info_bar;
921 } ActionWidgetsSubParserData;
924 attributes_start_element (GMarkupParseContext *context,
925 const gchar *element_name,
927 const gchar **values,
931 ActionWidgetsSubParserData *parser_data = (ActionWidgetsSubParserData*)user_data;
934 if (strcmp (element_name, "action-widget") == 0)
936 for (i = 0; names[i]; i++)
937 if (strcmp (names[i], "response") == 0)
938 parser_data->response = g_strdup (values[i]);
940 else if (strcmp (element_name, "action-widgets") == 0)
943 g_warning ("Unsupported tag for GtkInfoBar: %s\n", element_name);
947 attributes_text_element (GMarkupParseContext *context,
953 ActionWidgetsSubParserData *parser_data = (ActionWidgetsSubParserData*)user_data;
954 ActionWidgetInfo *item;
956 if (!parser_data->response)
959 item = g_new (ActionWidgetInfo, 1);
960 item->widget_name = g_strndup (text, text_len);
961 item->response_id = parser_data->response;
962 parser_data->items = g_slist_prepend (parser_data->items, item);
963 parser_data->response = NULL;
966 static const GMarkupParser attributes_parser =
968 attributes_start_element,
970 attributes_text_element,
974 gtk_info_bar_buildable_custom_tag_start (GtkBuildable *buildable,
977 const gchar *tagname,
978 GMarkupParser *parser,
981 ActionWidgetsSubParserData *parser_data;
986 if (strcmp (tagname, "action-widgets") == 0)
988 parser_data = g_slice_new0 (ActionWidgetsSubParserData);
989 parser_data->info_bar = GTK_INFO_BAR (buildable);
990 parser_data->items = NULL;
992 *parser = attributes_parser;
997 return parent_buildable_iface->custom_tag_start (buildable, builder, child,
998 tagname, parser, data);
1002 gtk_info_bar_buildable_custom_finished (GtkBuildable *buildable,
1003 GtkBuilder *builder,
1005 const gchar *tagname,
1009 ActionWidgetsSubParserData *parser_data;
1011 GtkInfoBar *info_bar;
1015 if (strcmp (tagname, "action-widgets"))
1017 parent_buildable_iface->custom_finished (buildable, builder, child,
1018 tagname, user_data);
1022 info_bar = GTK_INFO_BAR (buildable);
1023 parser_data = (ActionWidgetsSubParserData*)user_data;
1024 parser_data->items = g_slist_reverse (parser_data->items);
1026 for (l = parser_data->items; l; l = l->next)
1028 ActionWidgetInfo *item = l->data;
1030 object = gtk_builder_get_object (builder, item->widget_name);
1033 g_warning ("Unknown object %s specified in action-widgets of %s",
1035 gtk_buildable_get_name (GTK_BUILDABLE (buildable)));
1039 ad = get_response_data (GTK_WIDGET (object), TRUE);
1040 ad->response_id = atoi (item->response_id);
1042 if (GTK_IS_BUTTON (object))
1043 signal_id = g_signal_lookup ("clicked", GTK_TYPE_BUTTON);
1045 signal_id = GTK_WIDGET_GET_CLASS (object)->activate_signal;
1051 closure = g_cclosure_new_object (G_CALLBACK (action_widget_activated),
1052 G_OBJECT (info_bar));
1053 g_signal_connect_closure_by_id (object,
1060 if (ad->response_id == GTK_RESPONSE_HELP)
1061 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (info_bar->priv->action_area),
1062 GTK_WIDGET (object), TRUE);
1064 g_free (item->widget_name);
1065 g_free (item->response_id);
1068 g_slist_free (parser_data->items);
1069 g_slice_free (ActionWidgetsSubParserData, parser_data);
1073 * gtk_info_bar_set_message_type:
1074 * @info_bar: a #GtkInfoBar
1075 * @message_type: a #GtkMessageType
1077 * Sets the message type of the message area.
1078 * GTK+ uses this type to determine what color to use
1079 * when drawing the message area.
1084 gtk_info_bar_set_message_type (GtkInfoBar *info_bar,
1085 GtkMessageType message_type)
1087 GtkInfoBarPrivate *priv;
1090 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
1092 priv = info_bar->priv;
1094 if (priv->message_type != message_type)
1096 priv->message_type = message_type;
1098 gtk_widget_queue_draw (GTK_WIDGET (info_bar));
1100 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (info_bar));
1101 if (GTK_IS_ACCESSIBLE (atk_obj))
1104 const char *stock_id = NULL;
1106 atk_object_set_role (atk_obj, ATK_ROLE_ALERT);
1108 switch (message_type)
1110 case GTK_MESSAGE_INFO:
1111 stock_id = GTK_STOCK_DIALOG_INFO;
1114 case GTK_MESSAGE_QUESTION:
1115 stock_id = GTK_STOCK_DIALOG_QUESTION;
1118 case GTK_MESSAGE_WARNING:
1119 stock_id = GTK_STOCK_DIALOG_WARNING;
1122 case GTK_MESSAGE_ERROR:
1123 stock_id = GTK_STOCK_DIALOG_ERROR;
1126 case GTK_MESSAGE_OTHER:
1130 g_warning ("Unknown GtkMessageType %u", message_type);
1136 gtk_stock_lookup (stock_id, &item);
1137 atk_object_set_name (atk_obj, item.label);
1141 g_object_notify (G_OBJECT (info_bar), "message-type");
1146 * gtk_info_bar_get_message_type:
1147 * @info_bar: a #GtkInfoBar
1149 * Returns the message type of the message area.
1151 * Returns: the message type of the message area.
1156 gtk_info_bar_get_message_type (GtkInfoBar *info_bar)
1158 g_return_val_if_fail (GTK_IS_INFO_BAR (info_bar), GTK_MESSAGE_OTHER);
1160 return info_bar->priv->message_type;