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 "gtktypebuiltins.h"
53 * @short_description: Report important messages to the user
55 * @see_also: #GtkStatusbar, #GtkMessageDialog
57 * #GtkInfoBar is a widget that can be used to show messages to
58 * the user without showing a dialog. It is often temporarily shown
59 * at the top or bottom of a document. In contrast to #GtkDialog, which
60 * has a horizontal action area at the bottom, #GtkInfoBar has a
61 * vertical action area at the side.
63 * The API of #GtkInfoBar is very similar to #GtkDialog, allowing you
64 * to add buttons to the action area with gtk_info_bar_add_button() or
65 * gtk_info_bar_new_with_buttons(). The sensitivity of action widgets
66 * can be controlled with gtk_info_bar_set_response_sensitive().
67 * To add widgets to the main content area of a #GtkInfoBar, use
68 * gtk_info_bar_get_content_area() and add your widgets to the container.
70 * Similar to #GtkMessageDialog, the contents of a #GtkInfoBar can by
71 * classified as error message, warning, informational message, etc,
72 * by using gtk_info_bar_set_message_type(). GTK+ uses the message type
73 * to determine the background color of the message area.
76 * <title>Simple GtkInfoBar usage.</title>
78 * /* set up info bar */
79 * info_bar = gtk_info_bar_new ();
80 * gtk_widget_set_no_show_all (info_bar, TRUE);
81 * message_label = gtk_label_new ("");
82 * gtk_widget_show (message_label);
83 * content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
84 * gtk_container_add (GTK_CONTAINER (content_area), message_label);
85 * gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
86 * GTK_STOCK_OK, GTK_RESPONSE_OK);
87 * g_signal_connect (info_bar, "response",
88 * G_CALLBACK (gtk_widget_hide), NULL);
89 * gtk_table_attach (GTK_TABLE (table),
92 * GTK_EXPAND | GTK_FILL, 0,
97 * /* show an error message */
98 * gtk_label_set_text (GTK_LABEL (message_label), error_message);
99 * gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar),
100 * GTK_MESSAGE_ERROR);
101 * gtk_widget_show (info_bar);
105 * <refsect2 id="GtkInfoBar-BUILDER-UI">
106 * <title>GtkInfoBar as GtkBuildable</title>
108 * The GtkInfoBar implementation of the GtkBuildable interface exposes
109 * the content area and action area as internal children with the names
110 * "content_area" and "action_area".
113 * GtkInfoBar supports a custom <action-widgets> element, which
114 * can contain multiple <action-widget> elements. The "response"
115 * attribute specifies a numeric response, and the content of the element
116 * is the id of widget (which should be a child of the dialogs @action_area).
127 struct _GtkInfoBarPrivate
129 GtkWidget *content_area;
130 GtkWidget *action_area;
132 GtkMessageType message_type;
135 typedef struct _ResponseData ResponseData;
149 static guint signals[LAST_SIGNAL];
152 static void gtk_info_bar_set_property (GObject *object,
156 static void gtk_info_bar_get_property (GObject *object,
160 static void gtk_info_bar_style_updated (GtkWidget *widget);
161 static gboolean gtk_info_bar_draw (GtkWidget *widget,
163 static void gtk_info_bar_buildable_interface_init (GtkBuildableIface *iface);
164 static GObject *gtk_info_bar_buildable_get_internal_child (GtkBuildable *buildable,
166 const gchar *childname);
167 static gboolean gtk_info_bar_buildable_custom_tag_start (GtkBuildable *buildable,
170 const gchar *tagname,
171 GMarkupParser *parser,
173 static void gtk_info_bar_buildable_custom_finished (GtkBuildable *buildable,
176 const gchar *tagname,
180 G_DEFINE_TYPE_WITH_CODE (GtkInfoBar, gtk_info_bar, GTK_TYPE_HBOX,
181 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
182 gtk_info_bar_buildable_interface_init))
185 gtk_info_bar_set_property (GObject *object,
190 GtkInfoBar *info_bar = GTK_INFO_BAR (object);
194 case PROP_MESSAGE_TYPE:
195 gtk_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,
209 GtkInfoBar *info_bar = GTK_INFO_BAR (object);
213 case PROP_MESSAGE_TYPE:
214 g_value_set_enum (value, gtk_info_bar_get_message_type (info_bar));
217 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
223 gtk_info_bar_finalize (GObject *object)
225 G_OBJECT_CLASS (gtk_info_bar_parent_class)->finalize (object);
229 response_data_free (gpointer data)
231 g_slice_free (ResponseData, data);
234 static ResponseData *
235 get_response_data (GtkWidget *widget,
238 ResponseData *ad = g_object_get_data (G_OBJECT (widget),
239 "gtk-info-bar-response-data");
241 if (ad == NULL && create)
243 ad = g_slice_new (ResponseData);
245 g_object_set_data_full (G_OBJECT (widget),
246 I_("gtk-info-bar-response-data"),
255 find_button (GtkInfoBar *info_bar,
258 GList *children, *list;
259 GtkWidget *child = NULL;
261 children = gtk_container_get_children (GTK_CONTAINER (info_bar->priv->action_area));
263 for (list = children; list; list = list->next)
265 ResponseData *rd = get_response_data (list->data, FALSE);
267 if (rd && rd->response_id == response_id)
274 g_list_free (children);
280 gtk_info_bar_close (GtkInfoBar *info_bar)
282 if (!find_button (info_bar, GTK_RESPONSE_CANCEL))
285 gtk_info_bar_response (GTK_INFO_BAR (info_bar),
286 GTK_RESPONSE_CANCEL);
290 gtk_info_bar_draw (GtkWidget *widget,
293 GtkInfoBarPrivate *priv = GTK_INFO_BAR (widget)->priv;
294 const char* type_class[] = {
295 GTK_STYLE_CLASS_INFO,
296 GTK_STYLE_CLASS_WARNING,
297 GTK_STYLE_CLASS_QUESTION,
298 GTK_STYLE_CLASS_ERROR,
302 if (priv->message_type != GTK_MESSAGE_OTHER)
304 GtkStyleContext *context;
306 context = gtk_widget_get_style_context (widget);
308 gtk_style_context_save (context);
310 if (type_class[priv->message_type])
311 gtk_style_context_add_class (context,
312 type_class[priv->message_type]);
314 gtk_render_background (context, cr, 0, 0,
315 gtk_widget_get_allocated_width (widget),
316 gtk_widget_get_allocated_height (widget));
317 gtk_render_frame (context, cr, 0, 0,
318 gtk_widget_get_allocated_width (widget),
319 gtk_widget_get_allocated_height (widget));
321 gtk_style_context_restore (context);
324 if (GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->draw)
325 GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->draw (widget, cr);
331 gtk_info_bar_class_init (GtkInfoBarClass *klass)
333 GtkWidgetClass *widget_class;
334 GObjectClass *object_class;
335 GtkBindingSet *binding_set;
337 widget_class = GTK_WIDGET_CLASS (klass);
338 object_class = G_OBJECT_CLASS (klass);
340 object_class->get_property = gtk_info_bar_get_property;
341 object_class->set_property = gtk_info_bar_set_property;
342 object_class->finalize = gtk_info_bar_finalize;
344 widget_class->style_updated = gtk_info_bar_style_updated;
345 widget_class->draw = gtk_info_bar_draw;
347 klass->close = gtk_info_bar_close;
350 * GtkInfoBar:message-type:
352 * The type of the message.
354 * The type is used to determine the colors to use in the info bar.
355 * The following symbolic color names can by used to customize
357 * "info_fg_color", "info_bg_color",
358 * "warning_fg_color", "warning_bg_color",
359 * "question_fg_color", "question_bg_color",
360 * "error_fg_color", "error_bg_color".
361 * "other_fg_color", "other_bg_color".
363 * If the type is #GTK_MESSAGE_OTHER, no info bar is painted but the
364 * colors are still set.
368 g_object_class_install_property (object_class,
370 g_param_spec_enum ("message-type",
372 P_("The type of message"),
373 GTK_TYPE_MESSAGE_TYPE,
375 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
377 * GtkInfoBar::response:
378 * @info_bar: the object on which the signal is emitted
379 * @response_id: the response ID
381 * Emitted when an action widget is clicked or the application programmer
382 * calls gtk_dialog_response(). The @response_id depends on which action
383 * widget was clicked.
387 signals[RESPONSE] = g_signal_new (I_("response"),
388 G_OBJECT_CLASS_TYPE (klass),
390 G_STRUCT_OFFSET (GtkInfoBarClass, response),
392 g_cclosure_marshal_VOID__INT,
399 * The ::close signal is a
400 * <link linkend="keybinding-signals">keybinding signal</link>
401 * which gets emitted when the user uses a keybinding to dismiss
404 * The default binding for this signal is the Escape key.
408 signals[CLOSE] = g_signal_new (I_("close"),
409 G_OBJECT_CLASS_TYPE (klass),
410 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
411 G_STRUCT_OFFSET (GtkInfoBarClass, close),
413 g_cclosure_marshal_VOID__VOID,
417 * GtkInfoBar:content-area-border:
419 * The width of the border around the content
420 * content area of the info bar.
424 gtk_widget_class_install_style_property (widget_class,
425 g_param_spec_int ("content-area-border",
426 P_("Content area border"),
427 P_("Width of border around the content area"),
431 GTK_PARAM_READABLE));
434 * GtkInfoBar:content-area-spacing:
436 * The default spacing used between elements of the
437 * content area of the info bar.
441 gtk_widget_class_install_style_property (widget_class,
442 g_param_spec_int ("content-area-spacing",
443 P_("Content area spacing"),
444 P_("Spacing between elements of the area"),
448 GTK_PARAM_READABLE));
451 * GtkInfoBar:button-spacing:
453 * Spacing between buttons in the action area of the info bar.
457 gtk_widget_class_install_style_property (widget_class,
458 g_param_spec_int ("button-spacing",
459 P_("Button spacing"),
460 P_("Spacing between buttons"),
464 GTK_PARAM_READABLE));
467 * GtkInfoBar:action-area-border:
469 * Width of the border around the action area of the info bar.
473 gtk_widget_class_install_style_property (widget_class,
474 g_param_spec_int ("action-area-border",
475 P_("Action area border"),
476 P_("Width of border around the action area"),
480 GTK_PARAM_READABLE));
482 binding_set = gtk_binding_set_by_class (klass);
484 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "close", 0);
486 g_type_class_add_private (object_class, sizeof (GtkInfoBarPrivate));
490 gtk_info_bar_style_updated (GtkWidget *widget)
492 GtkInfoBar *info_bar = GTK_INFO_BAR (widget);
494 gint action_area_border;
495 gint content_area_spacing;
496 gint content_area_border;
498 gtk_widget_style_get (widget,
499 "button-spacing", &button_spacing,
500 "action-area-border", &action_area_border,
501 "content-area-spacing", &content_area_spacing,
502 "content-area-border", &content_area_border,
505 gtk_box_set_spacing (GTK_BOX (info_bar->priv->action_area), button_spacing);
506 gtk_container_set_border_width (GTK_CONTAINER (info_bar->priv->action_area),
508 gtk_box_set_spacing (GTK_BOX (info_bar->priv->content_area), content_area_spacing);
509 gtk_container_set_border_width (GTK_CONTAINER (info_bar->priv->content_area),
510 content_area_border);
514 gtk_info_bar_init (GtkInfoBar *info_bar)
516 GtkWidget *content_area;
517 GtkWidget *action_area;
519 gtk_widget_push_composite_child ();
521 info_bar->priv = G_TYPE_INSTANCE_GET_PRIVATE (info_bar,
525 content_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
526 gtk_widget_show (content_area);
527 gtk_box_pack_start (GTK_BOX (info_bar), content_area, TRUE, TRUE, 0);
529 action_area = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);
530 gtk_widget_show (action_area);
531 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
532 gtk_box_pack_start (GTK_BOX (info_bar), action_area, FALSE, TRUE, 0);
534 gtk_widget_set_app_paintable (GTK_WIDGET (info_bar), TRUE);
535 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (info_bar), TRUE);
537 info_bar->priv->content_area = content_area;
538 info_bar->priv->action_area = action_area;
540 gtk_widget_pop_composite_child ();
543 static GtkBuildableIface *parent_buildable_iface;
546 gtk_info_bar_buildable_interface_init (GtkBuildableIface *iface)
548 parent_buildable_iface = g_type_interface_peek_parent (iface);
549 iface->get_internal_child = gtk_info_bar_buildable_get_internal_child;
550 iface->custom_tag_start = gtk_info_bar_buildable_custom_tag_start;
551 iface->custom_finished = gtk_info_bar_buildable_custom_finished;
555 gtk_info_bar_buildable_get_internal_child (GtkBuildable *buildable,
557 const gchar *childname)
559 if (strcmp (childname, "content_area") == 0)
560 return G_OBJECT (GTK_INFO_BAR (buildable)->priv->content_area);
561 else if (strcmp (childname, "action_area") == 0)
562 return G_OBJECT (GTK_INFO_BAR (buildable)->priv->action_area);
564 return parent_buildable_iface->get_internal_child (buildable,
570 get_response_for_widget (GtkInfoBar *info_bar,
575 rd = get_response_data (widget, FALSE);
577 return GTK_RESPONSE_NONE;
579 return rd->response_id;
583 action_widget_activated (GtkWidget *widget,
584 GtkInfoBar *info_bar)
588 response_id = get_response_for_widget (info_bar, widget);
589 gtk_info_bar_response (info_bar, response_id);
593 * gtk_info_bar_add_action_widget:
594 * @info_bar: a #GtkInfoBar
595 * @child: an activatable widget
596 * @response_id: response ID for @child
598 * Add an activatable widget to the action area of a #GtkInfoBar,
599 * connecting a signal handler that will emit the #GtkInfoBar::response
600 * signal on the message area when the widget is activated. The widget
601 * is appended to the end of the message areas action area.
606 gtk_info_bar_add_action_widget (GtkInfoBar *info_bar,
613 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
614 g_return_if_fail (GTK_IS_WIDGET (child));
616 ad = get_response_data (child, TRUE);
618 ad->response_id = response_id;
620 if (GTK_IS_BUTTON (child))
621 signal_id = g_signal_lookup ("clicked", GTK_TYPE_BUTTON);
623 signal_id = GTK_WIDGET_GET_CLASS (child)->activate_signal;
629 closure = g_cclosure_new_object (G_CALLBACK (action_widget_activated),
630 G_OBJECT (info_bar));
631 g_signal_connect_closure_by_id (child, signal_id, 0, closure, FALSE);
634 g_warning ("Only 'activatable' widgets can be packed into the action area of a GtkInfoBar");
636 gtk_box_pack_end (GTK_BOX (info_bar->priv->action_area),
637 child, FALSE, FALSE, 0);
638 if (response_id == GTK_RESPONSE_HELP)
639 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (info_bar->priv->action_area),
644 * gtk_info_bar_get_action_area:
645 * @info_bar: a #GtkInfoBar
647 * Returns the action area of @info_bar.
649 * Returns: (transfer none): the action area
654 gtk_info_bar_get_action_area (GtkInfoBar *info_bar)
656 g_return_val_if_fail (GTK_IS_INFO_BAR (info_bar), NULL);
658 return info_bar->priv->action_area;
662 * gtk_info_bar_get_content_area:
663 * @info_bar: a #GtkInfoBar
665 * Returns the content area of @info_bar.
667 * Returns: (transfer none): the content area
672 gtk_info_bar_get_content_area (GtkInfoBar *info_bar)
674 g_return_val_if_fail (GTK_IS_INFO_BAR (info_bar), NULL);
676 return info_bar->priv->content_area;
680 * gtk_info_bar_add_button:
681 * @info_bar: a #GtkInfoBar
682 * @button_text: text of button, or stock ID
683 * @response_id: response ID for the button
685 * Adds a button with the given text (or a stock button, if button_text
686 * is a stock ID) and sets things up so that clicking the button will emit
687 * the "response" signal with the given response_id. The button is appended
688 * to the end of the info bars's action area. The button widget is
689 * returned, but usually you don't need it.
691 * Returns: (transfer none): the button widget that was added
696 gtk_info_bar_add_button (GtkInfoBar *info_bar,
697 const gchar *button_text,
702 g_return_val_if_fail (GTK_IS_INFO_BAR (info_bar), NULL);
703 g_return_val_if_fail (button_text != NULL, NULL);
705 button = gtk_button_new_from_stock (button_text);
707 gtk_widget_set_can_default (button, TRUE);
709 gtk_widget_show (button);
711 gtk_info_bar_add_action_widget (info_bar, button, response_id);
717 add_buttons_valist (GtkInfoBar *info_bar,
718 const gchar *first_button_text,
724 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
726 if (first_button_text == NULL)
729 text = first_button_text;
730 response_id = va_arg (args, gint);
734 gtk_info_bar_add_button (info_bar, text, response_id);
736 text = va_arg (args, gchar*);
740 response_id = va_arg (args, int);
745 * gtk_info_bar_add_buttons:
746 * @info_bar: a #GtkInfoBar
747 * @first_button_text: button text or stock ID
748 * @...: response ID for first button, then more text-response_id pairs,
751 * Adds more buttons, same as calling gtk_info_bar_add_button()
752 * repeatedly. The variable argument list should be %NULL-terminated
753 * as with gtk_info_bar_new_with_buttons(). Each button must have both
754 * text and response ID.
759 gtk_info_bar_add_buttons (GtkInfoBar *info_bar,
760 const gchar *first_button_text,
765 va_start (args, first_button_text);
766 add_buttons_valist (info_bar, first_button_text, args);
773 * Creates a new #GtkInfoBar object.
775 * Returns: a new #GtkInfoBar object
780 gtk_info_bar_new (void)
782 return g_object_new (GTK_TYPE_INFO_BAR, NULL);
786 * gtk_info_bar_new_with_buttons:
787 * @first_button_text: (allow-none): stock ID or text to go in first button, or %NULL
788 * @...: response ID for first button, then additional buttons, ending
791 * Creates a new #GtkInfoBar with buttons. Button text/response ID
792 * pairs should be listed, with a %NULL pointer ending the list.
793 * Button text can be either a stock ID such as %GTK_STOCK_OK, or
794 * some arbitrary text. A response ID can be any positive number,
795 * or one of the values in the #GtkResponseType enumeration. If the
796 * user clicks one of these dialog buttons, GtkInfoBar will emit
797 * the "response" signal with the corresponding response ID.
799 * Returns: a new #GtkInfoBar
802 gtk_info_bar_new_with_buttons (const gchar *first_button_text,
805 GtkInfoBar *info_bar;
808 info_bar = GTK_INFO_BAR (gtk_info_bar_new ());
810 va_start (args, first_button_text);
811 add_buttons_valist (info_bar, first_button_text, args);
814 return GTK_WIDGET (info_bar);
818 * gtk_info_bar_set_response_sensitive:
819 * @info_bar: a #GtkInfoBar
820 * @response_id: a response ID
821 * @setting: TRUE for sensitive
823 * Calls gtk_widget_set_sensitive (widget, setting) for each
824 * widget in the info bars's action area with the given response_id.
825 * A convenient way to sensitize/desensitize dialog buttons.
830 gtk_info_bar_set_response_sensitive (GtkInfoBar *info_bar,
834 GList *children, *list;
836 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
838 children = gtk_container_get_children (GTK_CONTAINER (info_bar->priv->action_area));
840 for (list = children; list; list = list->next)
842 GtkWidget *widget = list->data;
843 ResponseData *rd = get_response_data (widget, FALSE);
845 if (rd && rd->response_id == response_id)
846 gtk_widget_set_sensitive (widget, setting);
849 g_list_free (children);
853 * gtk_info_bar_set_default_response:
854 * @info_bar: a #GtkInfoBar
855 * @response_id: a response ID
857 * Sets the last widget in the info bar's action area with
858 * the given response_id as the default widget for the dialog.
859 * Pressing "Enter" normally activates the default widget.
861 * Note that this function currently requires @info_bar to
862 * be added to a widget hierarchy.
867 gtk_info_bar_set_default_response (GtkInfoBar *info_bar,
870 GList *children, *list;
872 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
874 children = gtk_container_get_children (GTK_CONTAINER (info_bar->priv->action_area));
876 for (list = children; list; list = list->next)
878 GtkWidget *widget = list->data;
879 ResponseData *rd = get_response_data (widget, FALSE);
881 if (rd && rd->response_id == response_id)
882 gtk_widget_grab_default (widget);
885 g_list_free (children);
889 * gtk_info_bar_response:
890 * @info_bar: a #GtkInfoBar
891 * @response_id: a response ID
893 * Emits the 'response' signal with the given @response_id.
898 gtk_info_bar_response (GtkInfoBar *info_bar,
901 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
903 g_signal_emit (info_bar, signals[RESPONSE], 0, response_id);
914 GtkInfoBar *info_bar;
918 } ActionWidgetsSubParserData;
921 attributes_start_element (GMarkupParseContext *context,
922 const gchar *element_name,
924 const gchar **values,
928 ActionWidgetsSubParserData *parser_data = (ActionWidgetsSubParserData*)user_data;
931 if (strcmp (element_name, "action-widget") == 0)
933 for (i = 0; names[i]; i++)
934 if (strcmp (names[i], "response") == 0)
935 parser_data->response = g_strdup (values[i]);
937 else if (strcmp (element_name, "action-widgets") == 0)
940 g_warning ("Unsupported tag for GtkInfoBar: %s\n", element_name);
944 attributes_text_element (GMarkupParseContext *context,
950 ActionWidgetsSubParserData *parser_data = (ActionWidgetsSubParserData*)user_data;
951 ActionWidgetInfo *item;
953 if (!parser_data->response)
956 item = g_new (ActionWidgetInfo, 1);
957 item->widget_name = g_strndup (text, text_len);
958 item->response_id = parser_data->response;
959 parser_data->items = g_slist_prepend (parser_data->items, item);
960 parser_data->response = NULL;
963 static const GMarkupParser attributes_parser =
965 attributes_start_element,
967 attributes_text_element,
971 gtk_info_bar_buildable_custom_tag_start (GtkBuildable *buildable,
974 const gchar *tagname,
975 GMarkupParser *parser,
978 ActionWidgetsSubParserData *parser_data;
983 if (strcmp (tagname, "action-widgets") == 0)
985 parser_data = g_slice_new0 (ActionWidgetsSubParserData);
986 parser_data->info_bar = GTK_INFO_BAR (buildable);
987 parser_data->items = NULL;
989 *parser = attributes_parser;
994 return parent_buildable_iface->custom_tag_start (buildable, builder, child,
995 tagname, parser, data);
999 gtk_info_bar_buildable_custom_finished (GtkBuildable *buildable,
1000 GtkBuilder *builder,
1002 const gchar *tagname,
1006 ActionWidgetsSubParserData *parser_data;
1008 GtkInfoBar *info_bar;
1012 if (strcmp (tagname, "action-widgets"))
1014 parent_buildable_iface->custom_finished (buildable, builder, child,
1015 tagname, user_data);
1019 info_bar = GTK_INFO_BAR (buildable);
1020 parser_data = (ActionWidgetsSubParserData*)user_data;
1021 parser_data->items = g_slist_reverse (parser_data->items);
1023 for (l = parser_data->items; l; l = l->next)
1025 ActionWidgetInfo *item = l->data;
1027 object = gtk_builder_get_object (builder, item->widget_name);
1030 g_warning ("Unknown object %s specified in action-widgets of %s",
1032 gtk_buildable_get_name (GTK_BUILDABLE (buildable)));
1036 ad = get_response_data (GTK_WIDGET (object), TRUE);
1037 ad->response_id = atoi (item->response_id);
1039 if (GTK_IS_BUTTON (object))
1040 signal_id = g_signal_lookup ("clicked", GTK_TYPE_BUTTON);
1042 signal_id = GTK_WIDGET_GET_CLASS (object)->activate_signal;
1048 closure = g_cclosure_new_object (G_CALLBACK (action_widget_activated),
1049 G_OBJECT (info_bar));
1050 g_signal_connect_closure_by_id (object,
1057 if (ad->response_id == GTK_RESPONSE_HELP)
1058 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (info_bar->priv->action_area),
1059 GTK_WIDGET (object), TRUE);
1061 g_free (item->widget_name);
1062 g_free (item->response_id);
1065 g_slist_free (parser_data->items);
1066 g_slice_free (ActionWidgetsSubParserData, parser_data);
1070 * gtk_info_bar_set_message_type:
1071 * @info_bar: a #GtkInfoBar
1072 * @message_type: a #GtkMessageType
1074 * Sets the message type of the message area.
1075 * GTK+ uses this type to determine what color to use
1076 * when drawing the message area.
1081 gtk_info_bar_set_message_type (GtkInfoBar *info_bar,
1082 GtkMessageType message_type)
1084 GtkInfoBarPrivate *priv;
1087 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
1089 priv = info_bar->priv;
1091 if (priv->message_type != message_type)
1093 priv->message_type = message_type;
1095 gtk_widget_queue_draw (GTK_WIDGET (info_bar));
1097 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (info_bar));
1098 if (GTK_IS_ACCESSIBLE (atk_obj))
1101 const char *stock_id = NULL;
1103 atk_object_set_role (atk_obj, ATK_ROLE_ALERT);
1105 switch (message_type)
1107 case GTK_MESSAGE_INFO:
1108 stock_id = GTK_STOCK_DIALOG_INFO;
1111 case GTK_MESSAGE_QUESTION:
1112 stock_id = GTK_STOCK_DIALOG_QUESTION;
1115 case GTK_MESSAGE_WARNING:
1116 stock_id = GTK_STOCK_DIALOG_WARNING;
1119 case GTK_MESSAGE_ERROR:
1120 stock_id = GTK_STOCK_DIALOG_ERROR;
1123 case GTK_MESSAGE_OTHER:
1127 g_warning ("Unknown GtkMessageType %u", message_type);
1133 gtk_stock_lookup (stock_id, &item);
1134 atk_object_set_name (atk_obj, item.label);
1138 g_object_notify (G_OBJECT (info_bar), "message-type");
1143 * gtk_info_bar_get_message_type:
1144 * @info_bar: a #GtkInfoBar
1146 * Returns the message type of the message area.
1148 * Returns: the message type of the message area.
1153 gtk_info_bar_get_message_type (GtkInfoBar *info_bar)
1155 g_return_val_if_fail (GTK_IS_INFO_BAR (info_bar), GTK_MESSAGE_OTHER);
1157 return info_bar->priv->message_type;