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];
149 static void gtk_info_bar_set_property (GObject *object,
153 static void gtk_info_bar_get_property (GObject *object,
157 static void gtk_info_bar_style_updated (GtkWidget *widget);
158 static void gtk_info_bar_get_preferred_width (GtkWidget *widget,
160 gint *natural_width);
161 static void gtk_info_bar_get_preferred_height (GtkWidget *widget,
162 gint *minimum_height,
163 gint *natural_height);
164 static gboolean gtk_info_bar_draw (GtkWidget *widget,
166 static void gtk_info_bar_buildable_interface_init (GtkBuildableIface *iface);
167 static GObject *gtk_info_bar_buildable_get_internal_child (GtkBuildable *buildable,
169 const gchar *childname);
170 static gboolean gtk_info_bar_buildable_custom_tag_start (GtkBuildable *buildable,
173 const gchar *tagname,
174 GMarkupParser *parser,
176 static void gtk_info_bar_buildable_custom_finished (GtkBuildable *buildable,
179 const gchar *tagname,
183 G_DEFINE_TYPE_WITH_CODE (GtkInfoBar, gtk_info_bar, GTK_TYPE_BOX,
184 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
185 gtk_info_bar_buildable_interface_init))
188 gtk_info_bar_set_property (GObject *object,
193 GtkInfoBar *info_bar = GTK_INFO_BAR (object);
197 case PROP_MESSAGE_TYPE:
198 gtk_info_bar_set_message_type (info_bar, g_value_get_enum (value));
201 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
207 gtk_info_bar_get_property (GObject *object,
212 GtkInfoBar *info_bar = GTK_INFO_BAR (object);
216 case PROP_MESSAGE_TYPE:
217 g_value_set_enum (value, gtk_info_bar_get_message_type (info_bar));
220 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
226 gtk_info_bar_finalize (GObject *object)
228 G_OBJECT_CLASS (gtk_info_bar_parent_class)->finalize (object);
232 response_data_free (gpointer data)
234 g_slice_free (ResponseData, data);
237 static ResponseData *
238 get_response_data (GtkWidget *widget,
241 ResponseData *ad = g_object_get_data (G_OBJECT (widget),
242 "gtk-info-bar-response-data");
244 if (ad == NULL && create)
246 ad = g_slice_new (ResponseData);
248 g_object_set_data_full (G_OBJECT (widget),
249 I_("gtk-info-bar-response-data"),
258 find_button (GtkInfoBar *info_bar,
261 GList *children, *list;
262 GtkWidget *child = NULL;
264 children = gtk_container_get_children (GTK_CONTAINER (info_bar->priv->action_area));
266 for (list = children; list; list = list->next)
268 ResponseData *rd = get_response_data (list->data, FALSE);
270 if (rd && rd->response_id == response_id)
277 g_list_free (children);
283 gtk_info_bar_close (GtkInfoBar *info_bar)
285 if (!find_button (info_bar, GTK_RESPONSE_CANCEL))
288 gtk_info_bar_response (GTK_INFO_BAR (info_bar),
289 GTK_RESPONSE_CANCEL);
293 get_padding_and_border (GtkWidget *widget,
296 GtkStyleContext *context;
300 context = gtk_widget_get_style_context (widget);
301 state = gtk_widget_get_state_flags (widget);
303 gtk_style_context_get_padding (context, state, border);
304 gtk_style_context_get_border (context, state, &tmp);
305 border->top += tmp.top;
306 border->right += tmp.right;
307 border->bottom += tmp.bottom;
308 border->left += tmp.left;
312 gtk_info_bar_get_preferred_width (GtkWidget *widget,
318 get_padding_and_border (widget, &border);
320 GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->get_preferred_width (widget,
325 *minimum_width += border.left + border.right;
327 *natural_width += border.left + border.right;
331 gtk_info_bar_get_preferred_height (GtkWidget *widget,
332 gint *minimum_height,
333 gint *natural_height)
337 get_padding_and_border (widget, &border);
339 GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->get_preferred_height (widget,
344 *minimum_height += border.top + border.bottom;
346 *natural_height += border.top + border.bottom;
350 gtk_info_bar_draw (GtkWidget *widget,
353 GtkStyleContext *context;
355 context = gtk_widget_get_style_context (widget);
357 gtk_render_background (context, cr, 0, 0,
358 gtk_widget_get_allocated_width (widget),
359 gtk_widget_get_allocated_height (widget));
360 gtk_render_frame (context, cr, 0, 0,
361 gtk_widget_get_allocated_width (widget),
362 gtk_widget_get_allocated_height (widget));
364 GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->draw (widget, cr);
370 gtk_info_bar_class_init (GtkInfoBarClass *klass)
372 GtkWidgetClass *widget_class;
373 GObjectClass *object_class;
374 GtkBindingSet *binding_set;
376 widget_class = GTK_WIDGET_CLASS (klass);
377 object_class = G_OBJECT_CLASS (klass);
379 object_class->get_property = gtk_info_bar_get_property;
380 object_class->set_property = gtk_info_bar_set_property;
381 object_class->finalize = gtk_info_bar_finalize;
383 widget_class->style_updated = gtk_info_bar_style_updated;
384 widget_class->get_preferred_width = gtk_info_bar_get_preferred_width;
385 widget_class->get_preferred_height = gtk_info_bar_get_preferred_height;
386 widget_class->draw = gtk_info_bar_draw;
388 klass->close = gtk_info_bar_close;
391 * GtkInfoBar:message-type:
393 * The type of the message.
395 * The type is used to determine the colors to use in the info bar.
396 * The following symbolic color names can by used to customize
398 * "info_fg_color", "info_bg_color",
399 * "warning_fg_color", "warning_bg_color",
400 * "question_fg_color", "question_bg_color",
401 * "error_fg_color", "error_bg_color".
402 * "other_fg_color", "other_bg_color".
404 * If the type is #GTK_MESSAGE_OTHER, no info bar is painted but the
405 * colors are still set.
409 g_object_class_install_property (object_class,
411 g_param_spec_enum ("message-type",
413 P_("The type of message"),
414 GTK_TYPE_MESSAGE_TYPE,
416 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
418 * GtkInfoBar::response:
419 * @info_bar: the object on which the signal is emitted
420 * @response_id: the response ID
422 * Emitted when an action widget is clicked or the application programmer
423 * calls gtk_dialog_response(). The @response_id depends on which action
424 * widget was clicked.
428 signals[RESPONSE] = g_signal_new (I_("response"),
429 G_OBJECT_CLASS_TYPE (klass),
431 G_STRUCT_OFFSET (GtkInfoBarClass, response),
433 g_cclosure_marshal_VOID__INT,
440 * The ::close signal is a
441 * <link linkend="keybinding-signals">keybinding signal</link>
442 * which gets emitted when the user uses a keybinding to dismiss
445 * The default binding for this signal is the Escape key.
449 signals[CLOSE] = g_signal_new (I_("close"),
450 G_OBJECT_CLASS_TYPE (klass),
451 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
452 G_STRUCT_OFFSET (GtkInfoBarClass, close),
454 g_cclosure_marshal_VOID__VOID,
458 * GtkInfoBar:content-area-border:
460 * The width of the border around the content
461 * content area of the info bar.
465 gtk_widget_class_install_style_property (widget_class,
466 g_param_spec_int ("content-area-border",
467 P_("Content area border"),
468 P_("Width of border around the content area"),
472 GTK_PARAM_READABLE));
475 * GtkInfoBar:content-area-spacing:
477 * The default spacing used between elements of the
478 * content area of the info bar.
482 gtk_widget_class_install_style_property (widget_class,
483 g_param_spec_int ("content-area-spacing",
484 P_("Content area spacing"),
485 P_("Spacing between elements of the area"),
489 GTK_PARAM_READABLE));
492 * GtkInfoBar:button-spacing:
494 * Spacing between buttons in the action area of the info bar.
498 gtk_widget_class_install_style_property (widget_class,
499 g_param_spec_int ("button-spacing",
500 P_("Button spacing"),
501 P_("Spacing between buttons"),
505 GTK_PARAM_READABLE));
508 * GtkInfoBar:action-area-border:
510 * Width of the border around the action area of the info bar.
514 gtk_widget_class_install_style_property (widget_class,
515 g_param_spec_int ("action-area-border",
516 P_("Action area border"),
517 P_("Width of border around the action area"),
521 GTK_PARAM_READABLE));
523 binding_set = gtk_binding_set_by_class (klass);
525 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "close", 0);
527 g_type_class_add_private (object_class, sizeof (GtkInfoBarPrivate));
531 gtk_info_bar_style_updated (GtkWidget *widget)
533 GtkInfoBar *info_bar = GTK_INFO_BAR (widget);
535 gint action_area_border;
536 gint content_area_spacing;
537 gint content_area_border;
539 GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->style_updated (widget);
541 gtk_widget_style_get (widget,
542 "button-spacing", &button_spacing,
543 "action-area-border", &action_area_border,
544 "content-area-spacing", &content_area_spacing,
545 "content-area-border", &content_area_border,
548 gtk_box_set_spacing (GTK_BOX (info_bar->priv->action_area), button_spacing);
549 gtk_container_set_border_width (GTK_CONTAINER (info_bar->priv->action_area),
551 gtk_box_set_spacing (GTK_BOX (info_bar->priv->content_area), content_area_spacing);
552 gtk_container_set_border_width (GTK_CONTAINER (info_bar->priv->content_area),
553 content_area_border);
557 gtk_info_bar_init (GtkInfoBar *info_bar)
559 GtkWidget *widget = GTK_WIDGET (info_bar);
560 GtkWidget *content_area;
561 GtkWidget *action_area;
563 gtk_widget_push_composite_child ();
565 info_bar->priv = G_TYPE_INSTANCE_GET_PRIVATE (info_bar,
569 content_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
570 gtk_widget_show (content_area);
571 gtk_box_pack_start (GTK_BOX (info_bar), content_area, TRUE, TRUE, 0);
573 action_area = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);
574 gtk_widget_show (action_area);
575 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
576 gtk_box_pack_start (GTK_BOX (info_bar), action_area, FALSE, TRUE, 0);
578 gtk_widget_set_app_paintable (widget, TRUE);
579 gtk_widget_set_redraw_on_allocate (widget, TRUE);
581 info_bar->priv->content_area = content_area;
582 info_bar->priv->action_area = action_area;
584 /* message-type is a CONSTRUCT property, so we init to a value
585 * different from its default to trigger its property setter
586 * during construction */
587 info_bar->priv->message_type = GTK_MESSAGE_OTHER;
589 gtk_widget_pop_composite_child ();
591 gtk_info_bar_style_updated (widget);
594 static GtkBuildableIface *parent_buildable_iface;
597 gtk_info_bar_buildable_interface_init (GtkBuildableIface *iface)
599 parent_buildable_iface = g_type_interface_peek_parent (iface);
600 iface->get_internal_child = gtk_info_bar_buildable_get_internal_child;
601 iface->custom_tag_start = gtk_info_bar_buildable_custom_tag_start;
602 iface->custom_finished = gtk_info_bar_buildable_custom_finished;
606 gtk_info_bar_buildable_get_internal_child (GtkBuildable *buildable,
608 const gchar *childname)
610 if (strcmp (childname, "content_area") == 0)
611 return G_OBJECT (GTK_INFO_BAR (buildable)->priv->content_area);
612 else if (strcmp (childname, "action_area") == 0)
613 return G_OBJECT (GTK_INFO_BAR (buildable)->priv->action_area);
615 return parent_buildable_iface->get_internal_child (buildable,
621 get_response_for_widget (GtkInfoBar *info_bar,
626 rd = get_response_data (widget, FALSE);
628 return GTK_RESPONSE_NONE;
630 return rd->response_id;
634 action_widget_activated (GtkWidget *widget,
635 GtkInfoBar *info_bar)
639 response_id = get_response_for_widget (info_bar, widget);
640 gtk_info_bar_response (info_bar, response_id);
644 * gtk_info_bar_add_action_widget:
645 * @info_bar: a #GtkInfoBar
646 * @child: an activatable widget
647 * @response_id: response ID for @child
649 * Add an activatable widget to the action area of a #GtkInfoBar,
650 * connecting a signal handler that will emit the #GtkInfoBar::response
651 * signal on the message area when the widget is activated. The widget
652 * is appended to the end of the message areas action area.
657 gtk_info_bar_add_action_widget (GtkInfoBar *info_bar,
664 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
665 g_return_if_fail (GTK_IS_WIDGET (child));
667 ad = get_response_data (child, TRUE);
669 ad->response_id = response_id;
671 if (GTK_IS_BUTTON (child))
672 signal_id = g_signal_lookup ("clicked", GTK_TYPE_BUTTON);
674 signal_id = GTK_WIDGET_GET_CLASS (child)->activate_signal;
680 closure = g_cclosure_new_object (G_CALLBACK (action_widget_activated),
681 G_OBJECT (info_bar));
682 g_signal_connect_closure_by_id (child, signal_id, 0, closure, FALSE);
685 g_warning ("Only 'activatable' widgets can be packed into the action area of a GtkInfoBar");
687 gtk_box_pack_end (GTK_BOX (info_bar->priv->action_area),
688 child, FALSE, FALSE, 0);
689 if (response_id == GTK_RESPONSE_HELP)
690 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (info_bar->priv->action_area),
695 * gtk_info_bar_get_action_area:
696 * @info_bar: a #GtkInfoBar
698 * Returns the action area of @info_bar.
700 * Returns: (transfer none): the action area
705 gtk_info_bar_get_action_area (GtkInfoBar *info_bar)
707 g_return_val_if_fail (GTK_IS_INFO_BAR (info_bar), NULL);
709 return info_bar->priv->action_area;
713 * gtk_info_bar_get_content_area:
714 * @info_bar: a #GtkInfoBar
716 * Returns the content area of @info_bar.
718 * Returns: (transfer none): the content area
723 gtk_info_bar_get_content_area (GtkInfoBar *info_bar)
725 g_return_val_if_fail (GTK_IS_INFO_BAR (info_bar), NULL);
727 return info_bar->priv->content_area;
731 * gtk_info_bar_add_button:
732 * @info_bar: a #GtkInfoBar
733 * @button_text: text of button, or stock ID
734 * @response_id: response ID for the button
736 * Adds a button with the given text (or a stock button, if button_text
737 * is a stock ID) and sets things up so that clicking the button will emit
738 * the "response" signal with the given response_id. The button is appended
739 * to the end of the info bars's action area. The button widget is
740 * returned, but usually you don't need it.
742 * Returns: (transfer none): the #GtkButton widget that was added
747 gtk_info_bar_add_button (GtkInfoBar *info_bar,
748 const gchar *button_text,
753 g_return_val_if_fail (GTK_IS_INFO_BAR (info_bar), NULL);
754 g_return_val_if_fail (button_text != NULL, NULL);
756 button = gtk_button_new_from_stock (button_text);
758 gtk_widget_set_can_default (button, TRUE);
760 gtk_widget_show (button);
762 gtk_info_bar_add_action_widget (info_bar, button, response_id);
768 add_buttons_valist (GtkInfoBar *info_bar,
769 const gchar *first_button_text,
775 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
777 if (first_button_text == NULL)
780 text = first_button_text;
781 response_id = va_arg (args, gint);
785 gtk_info_bar_add_button (info_bar, text, response_id);
787 text = va_arg (args, gchar*);
791 response_id = va_arg (args, int);
796 * gtk_info_bar_add_buttons:
797 * @info_bar: a #GtkInfoBar
798 * @first_button_text: button text or stock ID
799 * @...: response ID for first button, then more text-response_id pairs,
802 * Adds more buttons, same as calling gtk_info_bar_add_button()
803 * repeatedly. The variable argument list should be %NULL-terminated
804 * as with gtk_info_bar_new_with_buttons(). Each button must have both
805 * text and response ID.
810 gtk_info_bar_add_buttons (GtkInfoBar *info_bar,
811 const gchar *first_button_text,
816 va_start (args, first_button_text);
817 add_buttons_valist (info_bar, first_button_text, args);
824 * Creates a new #GtkInfoBar object.
826 * Returns: a new #GtkInfoBar object
831 gtk_info_bar_new (void)
833 return g_object_new (GTK_TYPE_INFO_BAR, NULL);
837 * gtk_info_bar_new_with_buttons:
838 * @first_button_text: (allow-none): stock ID or text to go in first button, or %NULL
839 * @...: response ID for first button, then additional buttons, ending
842 * Creates a new #GtkInfoBar with buttons. Button text/response ID
843 * pairs should be listed, with a %NULL pointer ending the list.
844 * Button text can be either a stock ID such as %GTK_STOCK_OK, or
845 * some arbitrary text. A response ID can be any positive number,
846 * or one of the values in the #GtkResponseType enumeration. If the
847 * user clicks one of these dialog buttons, GtkInfoBar will emit
848 * the "response" signal with the corresponding response ID.
850 * Returns: a new #GtkInfoBar
853 gtk_info_bar_new_with_buttons (const gchar *first_button_text,
856 GtkInfoBar *info_bar;
859 info_bar = GTK_INFO_BAR (gtk_info_bar_new ());
861 va_start (args, first_button_text);
862 add_buttons_valist (info_bar, first_button_text, args);
865 return GTK_WIDGET (info_bar);
869 * gtk_info_bar_set_response_sensitive:
870 * @info_bar: a #GtkInfoBar
871 * @response_id: a response ID
872 * @setting: TRUE for sensitive
874 * Calls gtk_widget_set_sensitive (widget, setting) for each
875 * widget in the info bars's action area with the given response_id.
876 * A convenient way to sensitize/desensitize dialog buttons.
881 gtk_info_bar_set_response_sensitive (GtkInfoBar *info_bar,
885 GList *children, *list;
887 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
889 children = gtk_container_get_children (GTK_CONTAINER (info_bar->priv->action_area));
891 for (list = children; list; list = list->next)
893 GtkWidget *widget = list->data;
894 ResponseData *rd = get_response_data (widget, FALSE);
896 if (rd && rd->response_id == response_id)
897 gtk_widget_set_sensitive (widget, setting);
900 g_list_free (children);
904 * gtk_info_bar_set_default_response:
905 * @info_bar: a #GtkInfoBar
906 * @response_id: a response ID
908 * Sets the last widget in the info bar's action area with
909 * the given response_id as the default widget for the dialog.
910 * Pressing "Enter" normally activates the default widget.
912 * Note that this function currently requires @info_bar to
913 * be added to a widget hierarchy.
918 gtk_info_bar_set_default_response (GtkInfoBar *info_bar,
921 GList *children, *list;
923 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
925 children = gtk_container_get_children (GTK_CONTAINER (info_bar->priv->action_area));
927 for (list = children; list; list = list->next)
929 GtkWidget *widget = list->data;
930 ResponseData *rd = get_response_data (widget, FALSE);
932 if (rd && rd->response_id == response_id)
933 gtk_widget_grab_default (widget);
936 g_list_free (children);
940 * gtk_info_bar_response:
941 * @info_bar: a #GtkInfoBar
942 * @response_id: a response ID
944 * Emits the 'response' signal with the given @response_id.
949 gtk_info_bar_response (GtkInfoBar *info_bar,
952 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
954 g_signal_emit (info_bar, signals[RESPONSE], 0, response_id);
965 GtkInfoBar *info_bar;
969 } ActionWidgetsSubParserData;
972 attributes_start_element (GMarkupParseContext *context,
973 const gchar *element_name,
975 const gchar **values,
979 ActionWidgetsSubParserData *parser_data = (ActionWidgetsSubParserData*)user_data;
982 if (strcmp (element_name, "action-widget") == 0)
984 for (i = 0; names[i]; i++)
985 if (strcmp (names[i], "response") == 0)
986 parser_data->response = g_strdup (values[i]);
988 else if (strcmp (element_name, "action-widgets") == 0)
991 g_warning ("Unsupported tag for GtkInfoBar: %s\n", element_name);
995 attributes_text_element (GMarkupParseContext *context,
1001 ActionWidgetsSubParserData *parser_data = (ActionWidgetsSubParserData*)user_data;
1002 ActionWidgetInfo *item;
1004 if (!parser_data->response)
1007 item = g_new (ActionWidgetInfo, 1);
1008 item->widget_name = g_strndup (text, text_len);
1009 item->response_id = parser_data->response;
1010 parser_data->items = g_slist_prepend (parser_data->items, item);
1011 parser_data->response = NULL;
1014 static const GMarkupParser attributes_parser =
1016 attributes_start_element,
1018 attributes_text_element,
1022 gtk_info_bar_buildable_custom_tag_start (GtkBuildable *buildable,
1023 GtkBuilder *builder,
1025 const gchar *tagname,
1026 GMarkupParser *parser,
1029 ActionWidgetsSubParserData *parser_data;
1034 if (strcmp (tagname, "action-widgets") == 0)
1036 parser_data = g_slice_new0 (ActionWidgetsSubParserData);
1037 parser_data->info_bar = GTK_INFO_BAR (buildable);
1038 parser_data->items = NULL;
1040 *parser = attributes_parser;
1041 *data = parser_data;
1045 return parent_buildable_iface->custom_tag_start (buildable, builder, child,
1046 tagname, parser, data);
1050 gtk_info_bar_buildable_custom_finished (GtkBuildable *buildable,
1051 GtkBuilder *builder,
1053 const gchar *tagname,
1057 ActionWidgetsSubParserData *parser_data;
1059 GtkInfoBar *info_bar;
1063 if (strcmp (tagname, "action-widgets"))
1065 parent_buildable_iface->custom_finished (buildable, builder, child,
1066 tagname, user_data);
1070 info_bar = GTK_INFO_BAR (buildable);
1071 parser_data = (ActionWidgetsSubParserData*)user_data;
1072 parser_data->items = g_slist_reverse (parser_data->items);
1074 for (l = parser_data->items; l; l = l->next)
1076 ActionWidgetInfo *item = l->data;
1078 object = gtk_builder_get_object (builder, item->widget_name);
1081 g_warning ("Unknown object %s specified in action-widgets of %s",
1083 gtk_buildable_get_name (GTK_BUILDABLE (buildable)));
1087 ad = get_response_data (GTK_WIDGET (object), TRUE);
1088 ad->response_id = atoi (item->response_id);
1090 if (GTK_IS_BUTTON (object))
1091 signal_id = g_signal_lookup ("clicked", GTK_TYPE_BUTTON);
1093 signal_id = GTK_WIDGET_GET_CLASS (object)->activate_signal;
1099 closure = g_cclosure_new_object (G_CALLBACK (action_widget_activated),
1100 G_OBJECT (info_bar));
1101 g_signal_connect_closure_by_id (object,
1108 if (ad->response_id == GTK_RESPONSE_HELP)
1109 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (info_bar->priv->action_area),
1110 GTK_WIDGET (object), TRUE);
1112 g_free (item->widget_name);
1113 g_free (item->response_id);
1116 g_slist_free (parser_data->items);
1117 g_slice_free (ActionWidgetsSubParserData, parser_data);
1121 * gtk_info_bar_set_message_type:
1122 * @info_bar: a #GtkInfoBar
1123 * @message_type: a #GtkMessageType
1125 * Sets the message type of the message area.
1126 * GTK+ uses this type to determine what color to use
1127 * when drawing the message area.
1132 gtk_info_bar_set_message_type (GtkInfoBar *info_bar,
1133 GtkMessageType message_type)
1135 GtkInfoBarPrivate *priv;
1137 g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
1139 priv = info_bar->priv;
1141 if (priv->message_type != message_type)
1143 GtkStyleContext *context;
1145 const char *type_class[] = {
1146 GTK_STYLE_CLASS_INFO,
1147 GTK_STYLE_CLASS_WARNING,
1148 GTK_STYLE_CLASS_QUESTION,
1149 GTK_STYLE_CLASS_ERROR,
1153 context = gtk_widget_get_style_context (GTK_WIDGET (info_bar));
1155 if (type_class[priv->message_type])
1156 gtk_style_context_remove_class (context, type_class[priv->message_type]);
1158 priv->message_type = message_type;
1160 gtk_widget_queue_draw (GTK_WIDGET (info_bar));
1162 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (info_bar));
1163 if (GTK_IS_ACCESSIBLE (atk_obj))
1166 const char *stock_id = NULL;
1168 atk_object_set_role (atk_obj, ATK_ROLE_ALERT);
1170 switch (message_type)
1172 case GTK_MESSAGE_INFO:
1173 stock_id = GTK_STOCK_DIALOG_INFO;
1176 case GTK_MESSAGE_QUESTION:
1177 stock_id = GTK_STOCK_DIALOG_QUESTION;
1180 case GTK_MESSAGE_WARNING:
1181 stock_id = GTK_STOCK_DIALOG_WARNING;
1184 case GTK_MESSAGE_ERROR:
1185 stock_id = GTK_STOCK_DIALOG_ERROR;
1188 case GTK_MESSAGE_OTHER:
1192 g_warning ("Unknown GtkMessageType %u", message_type);
1198 gtk_stock_lookup (stock_id, &item);
1199 atk_object_set_name (atk_obj, item.label);
1203 if (type_class[priv->message_type])
1204 gtk_style_context_add_class (context, type_class[priv->message_type]);
1206 g_object_notify (G_OBJECT (info_bar), "message-type");
1211 * gtk_info_bar_get_message_type:
1212 * @info_bar: a #GtkInfoBar
1214 * Returns the message type of the message area.
1216 * Returns: the message type of the message area.
1221 gtk_info_bar_get_message_type (GtkInfoBar *info_bar)
1223 g_return_val_if_fail (GTK_IS_INFO_BAR (info_bar), GTK_MESSAGE_OTHER);
1225 return info_bar->priv->message_type;