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, see <http://www.gnu.org/licenses/>.
22 * Modified by the gedit Team, 2005. See the AUTHORS file for a
23 * list of people on the gtk Team.
24 * See the gedit ChangeLog files for a list of changes.
26 * Modified by the GTK+ team, 2008-2009.
34 #include "gtkinfobar.h"
35 #include "gtkaccessible.h"
36 #include "gtkbuildable.h"
40 #include "gtkbutton.h"
42 #include "gtkbindings.h"
43 #include "gtkdialog.h"
45 #include "gtkprivate.h"
47 #include "gtkorientable.h"
48 #include "gtktypebuiltins.h"
52 * @short_description: Report important messages to the user
54 * @see_also: #GtkStatusbar, #GtkMessageDialog
56 * #GtkInfoBar is a widget that can be used to show messages to
57 * the user without showing a dialog. It is often temporarily shown
58 * at the top or bottom of a document. In contrast to #GtkDialog, which
59 * has a horizontal action area at the bottom, #GtkInfoBar has a
60 * vertical action area at the side.
62 * The API of #GtkInfoBar is very similar to #GtkDialog, allowing you
63 * to add buttons to the action area with gtk_info_bar_add_button() or
64 * gtk_info_bar_new_with_buttons(). The sensitivity of action widgets
65 * can be controlled with gtk_info_bar_set_response_sensitive().
66 * To add widgets to the main content area of a #GtkInfoBar, use
67 * gtk_info_bar_get_content_area() and add your widgets to the container.
69 * Similar to #GtkMessageDialog, the contents of a #GtkInfoBar can by
70 * classified as error message, warning, informational message, etc,
71 * by using gtk_info_bar_set_message_type(). GTK+ uses the message type
72 * to determine the background color of the message area.
75 * <title>Simple GtkInfoBar usage.</title>
77 * /* set up info bar */
78 * info_bar = gtk_info_bar_new ();
79 * gtk_widget_set_no_show_all (info_bar, TRUE);
80 * message_label = gtk_label_new ("");
81 * gtk_widget_show (message_label);
82 * content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
83 * gtk_container_add (GTK_CONTAINER (content_area), message_label);
84 * gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
85 * GTK_STOCK_OK, GTK_RESPONSE_OK);
86 * g_signal_connect (info_bar, "response",
87 * G_CALLBACK (gtk_widget_hide), NULL);
88 * gtk_grid_attach (GTK_GRID (grid),
94 * /* show an error message */
95 * gtk_label_set_text (GTK_LABEL (message_label), error_message);
96 * gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar),
98 * gtk_widget_show (info_bar);
102 * <refsect2 id="GtkInfoBar-BUILDER-UI">
103 * <title>GtkInfoBar as GtkBuildable</title>
105 * The GtkInfoBar implementation of the GtkBuildable interface exposes
106 * the content area and action area as internal children with the names
107 * "content_area" and "action_area".
110 * GtkInfoBar supports a custom <action-widgets> element, which
111 * can contain multiple <action-widget> elements. The "response"
112 * attribute specifies a numeric response, and the content of the element
113 * is the id of widget (which should be a child of the dialogs @action_area).
124 struct _GtkInfoBarPrivate
126 GtkWidget *content_area;
127 GtkWidget *action_area;
129 GtkMessageType message_type;
132 typedef struct _ResponseData ResponseData;
146 static guint signals[LAST_SIGNAL];
148 #define ACTION_AREA_DEFAULT_BORDER 5
149 #define ACTION_AREA_DEFAULT_SPACING 6
150 #define CONTENT_AREA_DEFAULT_BORDER 8
151 #define CONTENT_AREA_DEFAULT_SPACING 16
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_get_preferred_width (GtkWidget *widget,
163 gint *natural_width);
164 static void gtk_info_bar_get_preferred_height (GtkWidget *widget,
165 gint *minimum_height,
166 gint *natural_height);
167 static gboolean gtk_info_bar_draw (GtkWidget *widget,
169 static void gtk_info_bar_buildable_interface_init (GtkBuildableIface *iface);
170 static GObject *gtk_info_bar_buildable_get_internal_child (GtkBuildable *buildable,
172 const gchar *childname);
173 static gboolean gtk_info_bar_buildable_custom_tag_start (GtkBuildable *buildable,
176 const gchar *tagname,
177 GMarkupParser *parser,
179 static void gtk_info_bar_buildable_custom_finished (GtkBuildable *buildable,
182 const gchar *tagname,
186 G_DEFINE_TYPE_WITH_CODE (GtkInfoBar, gtk_info_bar, GTK_TYPE_BOX,
187 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
188 gtk_info_bar_buildable_interface_init))
191 gtk_info_bar_set_property (GObject *object,
196 GtkInfoBar *info_bar = GTK_INFO_BAR (object);
200 case PROP_MESSAGE_TYPE:
201 gtk_info_bar_set_message_type (info_bar, g_value_get_enum (value));
204 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
210 gtk_info_bar_get_property (GObject *object,
215 GtkInfoBar *info_bar = GTK_INFO_BAR (object);
219 case PROP_MESSAGE_TYPE:
220 g_value_set_enum (value, gtk_info_bar_get_message_type (info_bar));
223 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
229 gtk_info_bar_finalize (GObject *object)
231 G_OBJECT_CLASS (gtk_info_bar_parent_class)->finalize (object);
235 response_data_free (gpointer data)
237 g_slice_free (ResponseData, data);
240 static ResponseData *
241 get_response_data (GtkWidget *widget,
244 ResponseData *ad = g_object_get_data (G_OBJECT (widget),
245 "gtk-info-bar-response-data");
247 if (ad == NULL && create)
249 ad = g_slice_new (ResponseData);
251 g_object_set_data_full (G_OBJECT (widget),
252 I_("gtk-info-bar-response-data"),
261 find_button (GtkInfoBar *info_bar,
264 GList *children, *list;
265 GtkWidget *child = NULL;
267 children = gtk_container_get_children (GTK_CONTAINER (info_bar->priv->action_area));
269 for (list = children; list; list = list->next)
271 ResponseData *rd = get_response_data (list->data, FALSE);
273 if (rd && rd->response_id == response_id)
280 g_list_free (children);
286 gtk_info_bar_close (GtkInfoBar *info_bar)
288 if (!find_button (info_bar, GTK_RESPONSE_CANCEL))
291 gtk_info_bar_response (GTK_INFO_BAR (info_bar),
292 GTK_RESPONSE_CANCEL);
296 get_padding_and_border (GtkWidget *widget,
299 GtkStyleContext *context;
303 context = gtk_widget_get_style_context (widget);
304 state = gtk_widget_get_state_flags (widget);
306 gtk_style_context_get_padding (context, state, border);
307 gtk_style_context_get_border (context, state, &tmp);
308 border->top += tmp.top;
309 border->right += tmp.right;
310 border->bottom += tmp.bottom;
311 border->left += tmp.left;
315 gtk_info_bar_get_preferred_width (GtkWidget *widget,
321 get_padding_and_border (widget, &border);
323 GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->get_preferred_width (widget,
328 *minimum_width += border.left + border.right;
330 *natural_width += border.left + border.right;
334 gtk_info_bar_get_preferred_height (GtkWidget *widget,
335 gint *minimum_height,
336 gint *natural_height)
340 get_padding_and_border (widget, &border);
342 GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->get_preferred_height (widget,
347 *minimum_height += border.top + border.bottom;
349 *natural_height += border.top + border.bottom;
353 gtk_info_bar_draw (GtkWidget *widget,
356 GtkStyleContext *context;
358 context = gtk_widget_get_style_context (widget);
360 gtk_render_background (context, cr, 0, 0,
361 gtk_widget_get_allocated_width (widget),
362 gtk_widget_get_allocated_height (widget));
363 gtk_render_frame (context, cr, 0, 0,
364 gtk_widget_get_allocated_width (widget),
365 gtk_widget_get_allocated_height (widget));
367 GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->draw (widget, cr);
373 gtk_info_bar_class_init (GtkInfoBarClass *klass)
375 GtkWidgetClass *widget_class;
376 GObjectClass *object_class;
377 GtkBindingSet *binding_set;
379 widget_class = GTK_WIDGET_CLASS (klass);
380 object_class = G_OBJECT_CLASS (klass);
382 object_class->get_property = gtk_info_bar_get_property;
383 object_class->set_property = gtk_info_bar_set_property;
384 object_class->finalize = gtk_info_bar_finalize;
386 widget_class->get_preferred_width = gtk_info_bar_get_preferred_width;
387 widget_class->get_preferred_height = gtk_info_bar_get_preferred_height;
388 widget_class->draw = gtk_info_bar_draw;
390 klass->close = gtk_info_bar_close;
393 * GtkInfoBar:message-type:
395 * The type of the message.
397 * The type is used to determine the colors to use in the info bar.
398 * The following symbolic color names can by used to customize
400 * "info_fg_color", "info_bg_color",
401 * "warning_fg_color", "warning_bg_color",
402 * "question_fg_color", "question_bg_color",
403 * "error_fg_color", "error_bg_color".
404 * "other_fg_color", "other_bg_color".
406 * If the type is #GTK_MESSAGE_OTHER, no info bar is painted but the
407 * colors are still set.
411 g_object_class_install_property (object_class,
413 g_param_spec_enum ("message-type",
415 P_("The type of message"),
416 GTK_TYPE_MESSAGE_TYPE,
418 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
420 * GtkInfoBar::response:
421 * @info_bar: the object on which the signal is emitted
422 * @response_id: the response ID
424 * Emitted when an action widget is clicked or the application programmer
425 * calls gtk_dialog_response(). The @response_id depends on which action
426 * widget was clicked.
430 signals[RESPONSE] = g_signal_new (I_("response"),
431 G_OBJECT_CLASS_TYPE (klass),
433 G_STRUCT_OFFSET (GtkInfoBarClass, response),
435 g_cclosure_marshal_VOID__INT,
442 * The ::close signal is a
443 * <link linkend="keybinding-signals">keybinding signal</link>
444 * which gets emitted when the user uses a keybinding to dismiss
447 * The default binding for this signal is the Escape key.
451 signals[CLOSE] = g_signal_new (I_("close"),
452 G_OBJECT_CLASS_TYPE (klass),
453 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
454 G_STRUCT_OFFSET (GtkInfoBarClass, close),
456 g_cclosure_marshal_VOID__VOID,
460 * GtkInfoBar:content-area-border:
462 * The width of the border around the content
463 * content area of the info bar.
466 * Deprecated: 3.6: Use gtk_container_set_border_width()
468 gtk_widget_class_install_style_property (widget_class,
469 g_param_spec_int ("content-area-border",
470 P_("Content area border"),
471 P_("Width of border around the content area"),
474 CONTENT_AREA_DEFAULT_BORDER,
475 GTK_PARAM_READABLE));
478 * GtkInfoBar:content-area-spacing:
480 * The default spacing used between elements of the
481 * content area of the info bar.
484 * Deprecated: 3.6: Use gtk_box_set_spacing()
486 gtk_widget_class_install_style_property (widget_class,
487 g_param_spec_int ("content-area-spacing",
488 P_("Content area spacing"),
489 P_("Spacing between elements of the area"),
492 CONTENT_AREA_DEFAULT_SPACING,
493 GTK_PARAM_READABLE));
496 * GtkInfoBar:button-spacing:
498 * Spacing between buttons in the action area of the info bar.
501 * Deprecated: 3.6: Use gtk_box_set_spacing()
503 gtk_widget_class_install_style_property (widget_class,
504 g_param_spec_int ("button-spacing",
505 P_("Button spacing"),
506 P_("Spacing between buttons"),
509 ACTION_AREA_DEFAULT_SPACING,
510 GTK_PARAM_READABLE));
513 * GtkInfoBar:action-area-border:
515 * Width of the border around the action area of the info bar.
518 * Deprecated: 3.6: Use gtk_container_set_border_width()
520 gtk_widget_class_install_style_property (widget_class,
521 g_param_spec_int ("action-area-border",
522 P_("Action area border"),
523 P_("Width of border around the action area"),
526 ACTION_AREA_DEFAULT_BORDER,
527 GTK_PARAM_READABLE));
529 binding_set = gtk_binding_set_by_class (klass);
531 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "close", 0);
533 g_type_class_add_private (object_class, sizeof (GtkInfoBarPrivate));
537 gtk_info_bar_init (GtkInfoBar *info_bar)
539 GtkWidget *widget = GTK_WIDGET (info_bar);
540 GtkWidget *content_area;
541 GtkWidget *action_area;
543 gtk_widget_push_composite_child ();
545 info_bar->priv = G_TYPE_INSTANCE_GET_PRIVATE (info_bar,
549 content_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
550 gtk_widget_show (content_area);
551 gtk_box_pack_start (GTK_BOX (info_bar), content_area, TRUE, TRUE, 0);
553 action_area = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);
554 gtk_widget_show (action_area);
555 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
556 gtk_box_pack_start (GTK_BOX (info_bar), action_area, FALSE, TRUE, 0);
558 gtk_widget_set_app_paintable (widget, TRUE);
559 gtk_widget_set_redraw_on_allocate (widget, TRUE);
561 info_bar->priv->content_area = content_area;
562 info_bar->priv->action_area = action_area;
564 /* set default spacings */
565 gtk_box_set_spacing (GTK_BOX (info_bar->priv->action_area), ACTION_AREA_DEFAULT_SPACING);
566 gtk_container_set_border_width (GTK_CONTAINER (info_bar->priv->action_area), ACTION_AREA_DEFAULT_BORDER);
567 gtk_box_set_spacing (GTK_BOX (info_bar->priv->content_area), CONTENT_AREA_DEFAULT_SPACING);
568 gtk_container_set_border_width (GTK_CONTAINER (info_bar->priv->content_area), CONTENT_AREA_DEFAULT_BORDER);
570 /* message-type is a CONSTRUCT property, so we init to a value
571 * different from its default to trigger its property setter
572 * during construction */
573 info_bar->priv->message_type = GTK_MESSAGE_OTHER;
575 gtk_widget_pop_composite_child ();
578 static GtkBuildableIface *parent_buildable_iface;
581 gtk_info_bar_buildable_interface_init (GtkBuildableIface *iface)
583 parent_buildable_iface = g_type_interface_peek_parent (iface);
584 iface->get_internal_child = gtk_info_bar_buildable_get_internal_child;
585 iface->custom_tag_start = gtk_info_bar_buildable_custom_tag_start;
586 iface->custom_finished = gtk_info_bar_buildable_custom_finished;
590 gtk_info_bar_buildable_get_internal_child (GtkBuildable *buildable,
592 const gchar *childname)
594 if (strcmp (childname, "content_area") == 0)
595 return G_OBJECT (GTK_INFO_BAR (buildable)->priv->content_area);
596 else if (strcmp (childname, "action_area") == 0)
597 return G_OBJECT (GTK_INFO_BAR (buildable)->priv->action_area);
599 return parent_buildable_iface->get_internal_child (buildable,
605 get_response_for_widget (GtkInfoBar *info_bar,
610 rd = get_response_data (widget, FALSE);
612 return GTK_RESPONSE_NONE;
614 return rd->response_id;
618 action_widget_activated (GtkWidget *widget,
619 GtkInfoBar *info_bar)
623 response_id = get_response_for_widget (info_bar, widget);
624 gtk_info_bar_response (info_bar, response_id);
628 * gtk_info_bar_add_action_widget:
629 * @info_bar: a #GtkInfoBar
630 * @child: an activatable widget
631 * @response_id: response ID for @child
633 * Add an activatable widget to the action area of a #GtkInfoBar,
634 * connecting a signal handler that will emit the #GtkInfoBar::response
635 * signal on the message area when the widget is activated. The widget
636 * is appended to the end of the message areas action area.
641 gtk_info_bar_add_action_widget (GtkInfoBar *info_bar,
648 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
649 g_return_if_fail (GTK_IS_WIDGET (child));
651 ad = get_response_data (child, TRUE);
653 ad->response_id = response_id;
655 if (GTK_IS_BUTTON (child))
656 signal_id = g_signal_lookup ("clicked", GTK_TYPE_BUTTON);
658 signal_id = GTK_WIDGET_GET_CLASS (child)->activate_signal;
664 closure = g_cclosure_new_object (G_CALLBACK (action_widget_activated),
665 G_OBJECT (info_bar));
666 g_signal_connect_closure_by_id (child, signal_id, 0, closure, FALSE);
669 g_warning ("Only 'activatable' widgets can be packed into the action area of a GtkInfoBar");
671 gtk_box_pack_end (GTK_BOX (info_bar->priv->action_area),
672 child, FALSE, FALSE, 0);
673 if (response_id == GTK_RESPONSE_HELP)
674 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (info_bar->priv->action_area),
679 * gtk_info_bar_get_action_area:
680 * @info_bar: a #GtkInfoBar
682 * Returns the action area of @info_bar.
684 * Returns: (transfer none): the action area
689 gtk_info_bar_get_action_area (GtkInfoBar *info_bar)
691 g_return_val_if_fail (GTK_IS_INFO_BAR (info_bar), NULL);
693 return info_bar->priv->action_area;
697 * gtk_info_bar_get_content_area:
698 * @info_bar: a #GtkInfoBar
700 * Returns the content area of @info_bar.
702 * Returns: (transfer none): the content area
707 gtk_info_bar_get_content_area (GtkInfoBar *info_bar)
709 g_return_val_if_fail (GTK_IS_INFO_BAR (info_bar), NULL);
711 return info_bar->priv->content_area;
715 * gtk_info_bar_add_button:
716 * @info_bar: a #GtkInfoBar
717 * @button_text: text of button, or stock ID
718 * @response_id: response ID for the button
720 * Adds a button with the given text (or a stock button, if button_text
721 * is a stock ID) and sets things up so that clicking the button will emit
722 * the "response" signal with the given response_id. The button is appended
723 * to the end of the info bars's action area. The button widget is
724 * returned, but usually you don't need it.
726 * Returns: (transfer none): the #GtkButton widget that was added
731 gtk_info_bar_add_button (GtkInfoBar *info_bar,
732 const gchar *button_text,
737 g_return_val_if_fail (GTK_IS_INFO_BAR (info_bar), NULL);
738 g_return_val_if_fail (button_text != NULL, NULL);
740 button = gtk_button_new_from_stock (button_text);
742 gtk_widget_set_can_default (button, TRUE);
744 gtk_widget_show (button);
746 gtk_info_bar_add_action_widget (info_bar, button, response_id);
752 add_buttons_valist (GtkInfoBar *info_bar,
753 const gchar *first_button_text,
759 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
761 if (first_button_text == NULL)
764 text = first_button_text;
765 response_id = va_arg (args, gint);
769 gtk_info_bar_add_button (info_bar, text, response_id);
771 text = va_arg (args, gchar*);
775 response_id = va_arg (args, int);
780 * gtk_info_bar_add_buttons:
781 * @info_bar: a #GtkInfoBar
782 * @first_button_text: button text or stock ID
783 * @...: response ID for first button, then more text-response_id pairs,
786 * Adds more buttons, same as calling gtk_info_bar_add_button()
787 * repeatedly. The variable argument list should be %NULL-terminated
788 * as with gtk_info_bar_new_with_buttons(). Each button must have both
789 * text and response ID.
794 gtk_info_bar_add_buttons (GtkInfoBar *info_bar,
795 const gchar *first_button_text,
800 va_start (args, first_button_text);
801 add_buttons_valist (info_bar, first_button_text, args);
808 * Creates a new #GtkInfoBar object.
810 * Returns: a new #GtkInfoBar object
815 gtk_info_bar_new (void)
817 return g_object_new (GTK_TYPE_INFO_BAR, NULL);
821 * gtk_info_bar_new_with_buttons:
822 * @first_button_text: (allow-none): stock ID or text to go in first button, or %NULL
823 * @...: response ID for first button, then additional buttons, ending
826 * Creates a new #GtkInfoBar with buttons. Button text/response ID
827 * pairs should be listed, with a %NULL pointer ending the list.
828 * Button text can be either a stock ID such as %GTK_STOCK_OK, or
829 * some arbitrary text. A response ID can be any positive number,
830 * or one of the values in the #GtkResponseType enumeration. If the
831 * user clicks one of these dialog buttons, GtkInfoBar will emit
832 * the "response" signal with the corresponding response ID.
834 * Returns: a new #GtkInfoBar
837 gtk_info_bar_new_with_buttons (const gchar *first_button_text,
840 GtkInfoBar *info_bar;
843 info_bar = GTK_INFO_BAR (gtk_info_bar_new ());
845 va_start (args, first_button_text);
846 add_buttons_valist (info_bar, first_button_text, args);
849 return GTK_WIDGET (info_bar);
853 * gtk_info_bar_set_response_sensitive:
854 * @info_bar: a #GtkInfoBar
855 * @response_id: a response ID
856 * @setting: TRUE for sensitive
858 * Calls gtk_widget_set_sensitive (widget, setting) for each
859 * widget in the info bars's action area with the given response_id.
860 * A convenient way to sensitize/desensitize dialog buttons.
865 gtk_info_bar_set_response_sensitive (GtkInfoBar *info_bar,
869 GList *children, *list;
871 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
873 children = gtk_container_get_children (GTK_CONTAINER (info_bar->priv->action_area));
875 for (list = children; list; list = list->next)
877 GtkWidget *widget = list->data;
878 ResponseData *rd = get_response_data (widget, FALSE);
880 if (rd && rd->response_id == response_id)
881 gtk_widget_set_sensitive (widget, setting);
884 g_list_free (children);
888 * gtk_info_bar_set_default_response:
889 * @info_bar: a #GtkInfoBar
890 * @response_id: a response ID
892 * Sets the last widget in the info bar's action area with
893 * the given response_id as the default widget for the dialog.
894 * Pressing "Enter" normally activates the default widget.
896 * Note that this function currently requires @info_bar to
897 * be added to a widget hierarchy.
902 gtk_info_bar_set_default_response (GtkInfoBar *info_bar,
905 GList *children, *list;
907 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
909 children = gtk_container_get_children (GTK_CONTAINER (info_bar->priv->action_area));
911 for (list = children; list; list = list->next)
913 GtkWidget *widget = list->data;
914 ResponseData *rd = get_response_data (widget, FALSE);
916 if (rd && rd->response_id == response_id)
917 gtk_widget_grab_default (widget);
920 g_list_free (children);
924 * gtk_info_bar_response:
925 * @info_bar: a #GtkInfoBar
926 * @response_id: a response ID
928 * Emits the 'response' signal with the given @response_id.
933 gtk_info_bar_response (GtkInfoBar *info_bar,
936 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
938 g_signal_emit (info_bar, signals[RESPONSE], 0, response_id);
949 GtkInfoBar *info_bar;
953 } ActionWidgetsSubParserData;
956 attributes_start_element (GMarkupParseContext *context,
957 const gchar *element_name,
959 const gchar **values,
963 ActionWidgetsSubParserData *parser_data = (ActionWidgetsSubParserData*)user_data;
966 if (strcmp (element_name, "action-widget") == 0)
968 for (i = 0; names[i]; i++)
969 if (strcmp (names[i], "response") == 0)
970 parser_data->response = g_strdup (values[i]);
972 else if (strcmp (element_name, "action-widgets") == 0)
975 g_warning ("Unsupported tag for GtkInfoBar: %s\n", element_name);
979 attributes_text_element (GMarkupParseContext *context,
985 ActionWidgetsSubParserData *parser_data = (ActionWidgetsSubParserData*)user_data;
986 ActionWidgetInfo *item;
988 if (!parser_data->response)
991 item = g_new (ActionWidgetInfo, 1);
992 item->widget_name = g_strndup (text, text_len);
993 item->response_id = parser_data->response;
994 parser_data->items = g_slist_prepend (parser_data->items, item);
995 parser_data->response = NULL;
998 static const GMarkupParser attributes_parser =
1000 attributes_start_element,
1002 attributes_text_element,
1006 gtk_info_bar_buildable_custom_tag_start (GtkBuildable *buildable,
1007 GtkBuilder *builder,
1009 const gchar *tagname,
1010 GMarkupParser *parser,
1013 ActionWidgetsSubParserData *parser_data;
1015 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
1016 tagname, parser, data))
1019 if (!child && strcmp (tagname, "action-widgets") == 0)
1021 parser_data = g_slice_new0 (ActionWidgetsSubParserData);
1022 parser_data->info_bar = GTK_INFO_BAR (buildable);
1023 parser_data->items = NULL;
1025 *parser = attributes_parser;
1026 *data = parser_data;
1034 gtk_info_bar_buildable_custom_finished (GtkBuildable *buildable,
1035 GtkBuilder *builder,
1037 const gchar *tagname,
1041 ActionWidgetsSubParserData *parser_data;
1043 GtkInfoBar *info_bar;
1047 if (strcmp (tagname, "action-widgets"))
1049 parent_buildable_iface->custom_finished (buildable, builder, child,
1050 tagname, user_data);
1054 info_bar = GTK_INFO_BAR (buildable);
1055 parser_data = (ActionWidgetsSubParserData*)user_data;
1056 parser_data->items = g_slist_reverse (parser_data->items);
1058 for (l = parser_data->items; l; l = l->next)
1060 ActionWidgetInfo *item = l->data;
1062 object = gtk_builder_get_object (builder, item->widget_name);
1065 g_warning ("Unknown object %s specified in action-widgets of %s",
1067 gtk_buildable_get_name (GTK_BUILDABLE (buildable)));
1071 ad = get_response_data (GTK_WIDGET (object), TRUE);
1072 ad->response_id = atoi (item->response_id);
1074 if (GTK_IS_BUTTON (object))
1075 signal_id = g_signal_lookup ("clicked", GTK_TYPE_BUTTON);
1077 signal_id = GTK_WIDGET_GET_CLASS (object)->activate_signal;
1083 closure = g_cclosure_new_object (G_CALLBACK (action_widget_activated),
1084 G_OBJECT (info_bar));
1085 g_signal_connect_closure_by_id (object,
1092 if (ad->response_id == GTK_RESPONSE_HELP)
1093 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (info_bar->priv->action_area),
1094 GTK_WIDGET (object), TRUE);
1096 g_free (item->widget_name);
1097 g_free (item->response_id);
1100 g_slist_free (parser_data->items);
1101 g_slice_free (ActionWidgetsSubParserData, parser_data);
1105 * gtk_info_bar_set_message_type:
1106 * @info_bar: a #GtkInfoBar
1107 * @message_type: a #GtkMessageType
1109 * Sets the message type of the message area.
1110 * GTK+ uses this type to determine what color to use
1111 * when drawing the message area.
1116 gtk_info_bar_set_message_type (GtkInfoBar *info_bar,
1117 GtkMessageType message_type)
1119 GtkInfoBarPrivate *priv;
1121 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
1123 priv = info_bar->priv;
1125 if (priv->message_type != message_type)
1127 GtkStyleContext *context;
1129 const char *type_class[] = {
1130 GTK_STYLE_CLASS_INFO,
1131 GTK_STYLE_CLASS_WARNING,
1132 GTK_STYLE_CLASS_QUESTION,
1133 GTK_STYLE_CLASS_ERROR,
1137 context = gtk_widget_get_style_context (GTK_WIDGET (info_bar));
1139 if (type_class[priv->message_type])
1140 gtk_style_context_remove_class (context, type_class[priv->message_type]);
1142 priv->message_type = message_type;
1144 gtk_widget_queue_draw (GTK_WIDGET (info_bar));
1146 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (info_bar));
1147 if (GTK_IS_ACCESSIBLE (atk_obj))
1150 const char *stock_id = NULL;
1152 atk_object_set_role (atk_obj, ATK_ROLE_ALERT);
1154 switch (message_type)
1156 case GTK_MESSAGE_INFO:
1157 stock_id = GTK_STOCK_DIALOG_INFO;
1160 case GTK_MESSAGE_QUESTION:
1161 stock_id = GTK_STOCK_DIALOG_QUESTION;
1164 case GTK_MESSAGE_WARNING:
1165 stock_id = GTK_STOCK_DIALOG_WARNING;
1168 case GTK_MESSAGE_ERROR:
1169 stock_id = GTK_STOCK_DIALOG_ERROR;
1172 case GTK_MESSAGE_OTHER:
1176 g_warning ("Unknown GtkMessageType %u", message_type);
1182 gtk_stock_lookup (stock_id, &item);
1183 atk_object_set_name (atk_obj, item.label);
1187 if (type_class[priv->message_type])
1188 gtk_style_context_add_class (context, type_class[priv->message_type]);
1190 g_object_notify (G_OBJECT (info_bar), "message-type");
1195 * gtk_info_bar_get_message_type:
1196 * @info_bar: a #GtkInfoBar
1198 * Returns the message type of the message area.
1200 * Returns: the message type of the message area.
1205 gtk_info_bar_get_message_type (GtkInfoBar *info_bar)
1207 g_return_val_if_fail (GTK_IS_INFO_BAR (info_bar), GTK_MESSAGE_OTHER);
1209 return info_bar->priv->message_type;