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 "evinfobar.h"
38 #include <gdk/gdkkeysyms.h>
42 * @short_description: Report important messages to the user
44 * @see_also: #GtkStatusbar, #GtkMessageDialog
46 * #GtkInfoBar is a widget that can be used to show messages to
47 * the user without showing a dialog. It is often temporarily shown
48 * at the top or bottom of a document. In contrast to #GtkDialog, which
49 * has a horizontal action area at the bottom, #GtkInfoBar has a
50 * vertical action area at the side.
52 * The API of #GtkInfoBar is very similar to #GtkDialog, allowing you
53 * to add buttons to the action area with gtk_info_bar_add_button() or
54 * gtk_info_bar_new_with_buttons(). The sensitivity of action widgets
55 * can be controlled with gtk_info_bar_set_response_sensitive().
56 * To add widgets to the main content area of a #GtkInfoBar, use
57 * gtk_info_bar_get_content_area() and add your widgets to the container.
59 * Similar to #GtkMessageDialog, the contents of a #GtkInfoBar can by
60 * classified as error message, warning, informational message, etc,
61 * by using gtk_info_bar_set_message_type(). GTK+ uses the message type
62 * to determine the background color of the message area.
65 * <title>Simple GtkInfoBar usage.</title>
67 * /* set up info bar */
68 * info_bar = gtk_info_bar_new ();
69 * gtk_widget_set_no_show_all (info_bar, TRUE);
70 * message_label = gtk_label_new ("");
71 * gtk_widget_show (message_label);
72 * content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
73 * gtk_container_add (GTK_CONTAINER (content_area), message_label);
74 * gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
75 * GTK_STOCK_OK, GTK_RESPONSE_OK);
76 * g_signal_connect (info_bar, "response",
77 * G_CALLBACK (gtk_widget_hide), NULL);
78 * gtk_table_attach (GTK_TABLE (table),
81 * GTK_EXPAND | GTK_FILL, 0,
86 * /* show an error message */
87 * gtk_label_set_text (GTK_LABEL (message_label), error_message);
88 * gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar),
90 * gtk_widget_show (info_bar);
94 * <refsect2 id="GtkInfoBar-BUILDER-UI">
95 * <title>GtkInfoBar as GtkBuildable</title>
97 * The GtkInfoBar implementation of the GtkBuildable interface exposes
98 * the content area and action area as internal children with the names
99 * "content_area" and "action_area".
102 * GtkInfoBar supports a custom <action-widgets> element, which
103 * can contain multiple <action-widget> elements. The "response"
104 * attribute specifies a numeric response, and the content of the element
105 * is the id of widget (which should be a child of the dialogs @action_area).
110 #define GTK_INFO_BAR_GET_PRIVATE(object) \
111 (G_TYPE_INSTANCE_GET_PRIVATE ((object), \
121 struct _EvInfoBarPrivate
123 GtkWidget *content_area;
124 GtkWidget *action_area;
126 GtkMessageType message_type;
129 typedef struct _ResponseData ResponseData;
143 static guint signals[LAST_SIGNAL];
146 static void gtk_info_bar_set_property (GObject *object,
150 static void gtk_info_bar_get_property (GObject *object,
154 static void gtk_info_bar_style_set (GtkWidget *widget,
155 GtkStyle *prev_style);
156 static gboolean gtk_info_bar_expose (GtkWidget *widget,
157 GdkEventExpose *event);
158 static void gtk_info_bar_buildable_interface_init (GtkBuildableIface *iface);
159 static GObject *gtk_info_bar_buildable_get_internal_child (GtkBuildable *buildable,
161 const gchar *childname);
162 static gboolean gtk_info_bar_buildable_custom_tag_start (GtkBuildable *buildable,
165 const gchar *tagname,
166 GMarkupParser *parser,
168 static void gtk_info_bar_buildable_custom_finished (GtkBuildable *buildable,
171 const gchar *tagname,
175 G_DEFINE_TYPE_WITH_CODE (EvInfoBar, ev_info_bar, GTK_TYPE_HBOX,
176 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
177 gtk_info_bar_buildable_interface_init))
180 gtk_info_bar_set_property (GObject *object,
186 EvInfoBarPrivate *priv;
188 info_bar = EV_INFO_BAR (object);
189 priv = GTK_INFO_BAR_GET_PRIVATE (info_bar);
193 case PROP_MESSAGE_TYPE:
194 ev_info_bar_set_message_type (info_bar, g_value_get_enum (value));
197 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
203 gtk_info_bar_get_property (GObject *object,
209 EvInfoBarPrivate *priv;
211 info_bar = EV_INFO_BAR (object);
212 priv = GTK_INFO_BAR_GET_PRIVATE (info_bar);
216 case PROP_MESSAGE_TYPE:
217 g_value_set_enum (value, ev_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 (ev_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 "gtk-info-bar-response-data",
258 find_button (EvInfoBar *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 (EvInfoBar *info_bar)
285 if (!find_button (info_bar, GTK_RESPONSE_CANCEL))
288 ev_info_bar_response (EV_INFO_BAR (info_bar),
289 GTK_RESPONSE_CANCEL);
293 gtk_info_bar_expose (GtkWidget *widget,
294 GdkEventExpose *event)
296 EvInfoBarPrivate *priv = GTK_INFO_BAR_GET_PRIVATE (widget);
297 const char* type_detail[] = {
305 if (priv->message_type != GTK_MESSAGE_OTHER)
309 detail = type_detail[priv->message_type];
311 gtk_paint_box (widget->style,
318 widget->allocation.x,
319 widget->allocation.y,
320 widget->allocation.width,
321 widget->allocation.height);
324 if (GTK_WIDGET_CLASS (ev_info_bar_parent_class)->expose_event)
325 GTK_WIDGET_CLASS (ev_info_bar_parent_class)->expose_event (widget, event);
331 ev_info_bar_class_init (EvInfoBarClass *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_set = gtk_info_bar_style_set;
345 widget_class->expose_event = gtk_info_bar_expose;
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 "The type of message",
373 GTK_TYPE_MESSAGE_TYPE,
375 G_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 ("response",
388 G_OBJECT_CLASS_TYPE (klass),
390 G_STRUCT_OFFSET (EvInfoBarClass, 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 ("close",
409 G_OBJECT_CLASS_TYPE (klass),
410 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
411 G_STRUCT_OFFSET (EvInfoBarClass, 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 "Content area border",
427 "Width of border around the content area",
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 "Content area spacing",
444 "Spacing between elements of the area",
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",
460 "Spacing between buttons",
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 "Action area border",
476 "Width of border around the action area",
482 binding_set = gtk_binding_set_by_class (klass);
484 gtk_binding_entry_add_signal (binding_set, GDK_Escape, 0, "close", 0);
486 g_type_class_add_private (object_class, sizeof (EvInfoBarPrivate));
490 gtk_info_bar_update_colors (EvInfoBar *info_bar)
492 GtkWidget *widget = (GtkWidget*)info_bar;
493 EvInfoBarPrivate *priv;
494 GdkColor info_default_border_color = { 0, 0xb800, 0xad00, 0x9d00 };
495 GdkColor info_default_fill_color = { 0, 0xff00, 0xff00, 0xbf00 };
496 GdkColor warning_default_border_color = { 0, 0xb000, 0x7a00, 0x2b00 };
497 GdkColor warning_default_fill_color = { 0, 0xfc00, 0xaf00, 0x3e00 };
498 GdkColor question_default_border_color = { 0, 0x6200, 0x7b00, 0xd960 };
499 GdkColor question_default_fill_color = { 0, 0x8c00, 0xb000, 0xd700 };
500 GdkColor error_default_border_color = { 0, 0xa800, 0x2700, 0x2700 };
501 GdkColor error_default_fill_color = { 0, 0xf000, 0x3800, 0x3800 };
502 GdkColor other_default_border_color = { 0, 0xb800, 0xad00, 0x9d00 };
503 GdkColor other_default_fill_color = { 0, 0xff00, 0xff00, 0xbf00 };
505 GdkColor sym_fg, sym_bg;
507 const char* fg_color_name[] = {
514 const char* bg_color_name[] = {
522 priv = GTK_INFO_BAR_GET_PRIVATE (info_bar);
523 style = gtk_widget_get_style (widget);
525 if (gtk_style_lookup_color (style, fg_color_name[priv->message_type], &sym_fg) &&
526 gtk_style_lookup_color (style, bg_color_name[priv->message_type], &sym_bg))
533 switch (priv->message_type)
535 case GTK_MESSAGE_INFO:
536 fg = &info_default_border_color;
537 bg = &info_default_fill_color;
540 case GTK_MESSAGE_WARNING:
541 fg = &warning_default_border_color;
542 bg = &warning_default_fill_color;
545 case GTK_MESSAGE_QUESTION:
546 fg = &question_default_border_color;
547 bg = &question_default_fill_color;
550 case GTK_MESSAGE_ERROR:
551 fg = &error_default_border_color;
552 bg = &error_default_fill_color;
555 case GTK_MESSAGE_OTHER:
556 fg = &other_default_border_color;
557 bg = &other_default_fill_color;
562 if (!gdk_color_equal (bg, &widget->style->bg[GTK_STATE_NORMAL]))
563 gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, bg);
564 if (!gdk_color_equal (fg, &widget->style->fg[GTK_STATE_NORMAL]))
565 gtk_widget_modify_fg (widget, GTK_STATE_NORMAL, fg);
569 gtk_info_bar_style_set (GtkWidget *widget,
570 GtkStyle *prev_style)
572 EvInfoBar *info_bar = EV_INFO_BAR (widget);
574 gint action_area_border;
575 gint content_area_spacing;
576 gint content_area_border;
578 gtk_widget_style_get (widget,
579 "button-spacing", &button_spacing,
580 "action-area-border", &action_area_border,
581 "content-area-spacing", &content_area_spacing,
582 "content-area-border", &content_area_border,
585 gtk_box_set_spacing (GTK_BOX (info_bar->priv->action_area), button_spacing);
586 gtk_container_set_border_width (GTK_CONTAINER (info_bar->priv->action_area),
588 gtk_box_set_spacing (GTK_BOX (info_bar->priv->content_area), content_area_spacing);
589 gtk_container_set_border_width (GTK_CONTAINER (info_bar->priv->content_area),
590 content_area_border);
592 gtk_info_bar_update_colors (info_bar);
596 ev_info_bar_init (EvInfoBar *info_bar)
598 GtkWidget *content_area;
599 GtkWidget *action_area;
601 gtk_widget_push_composite_child ();
603 info_bar->priv = GTK_INFO_BAR_GET_PRIVATE (info_bar);
605 content_area = gtk_hbox_new (FALSE, 0);
606 gtk_widget_show (content_area);
607 gtk_box_pack_start (GTK_BOX (info_bar), content_area, TRUE, TRUE, 0);
609 action_area = gtk_vbutton_box_new ();
610 gtk_widget_show (action_area);
611 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
612 gtk_box_pack_start (GTK_BOX (info_bar), action_area, FALSE, TRUE, 0);
614 gtk_widget_set_app_paintable (GTK_WIDGET (info_bar), TRUE);
615 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (info_bar), TRUE);
617 info_bar->priv->content_area = content_area;
618 info_bar->priv->action_area = action_area;
620 gtk_widget_pop_composite_child ();
623 static GtkBuildableIface *parent_buildable_iface;
626 gtk_info_bar_buildable_interface_init (GtkBuildableIface *iface)
628 parent_buildable_iface = g_type_interface_peek_parent (iface);
629 iface->get_internal_child = gtk_info_bar_buildable_get_internal_child;
630 iface->custom_tag_start = gtk_info_bar_buildable_custom_tag_start;
631 iface->custom_finished = gtk_info_bar_buildable_custom_finished;
635 gtk_info_bar_buildable_get_internal_child (GtkBuildable *buildable,
637 const gchar *childname)
639 if (strcmp (childname, "content_area") == 0)
640 return G_OBJECT (EV_INFO_BAR (buildable)->priv->content_area);
641 else if (strcmp (childname, "action_area") == 0)
642 return G_OBJECT (EV_INFO_BAR (buildable)->priv->action_area);
644 return parent_buildable_iface->get_internal_child (buildable,
650 get_response_for_widget (EvInfoBar *info_bar,
655 rd = get_response_data (widget, FALSE);
657 return GTK_RESPONSE_NONE;
659 return rd->response_id;
663 action_widget_activated (GtkWidget *widget,
668 response_id = get_response_for_widget (info_bar, widget);
669 ev_info_bar_response (info_bar, response_id);
673 * gtk_info_bar_add_action_widget:
674 * @info_bar: a #GtkInfoBar
675 * @child: an activatable widget
676 * @response_id: response ID for @child
678 * Add an activatable widget to the action area of a #GtkInfoBar,
679 * connecting a signal handler that will emit the #GtkInfoBar::response
680 * signal on the message area when the widget is activated. The widget
681 * is appended to the end of the message areas action area.
686 ev_info_bar_add_action_widget (EvInfoBar *info_bar,
693 g_return_if_fail (EV_IS_INFO_BAR (info_bar));
694 g_return_if_fail (GTK_IS_WIDGET (child));
696 ad = get_response_data (child, TRUE);
698 ad->response_id = response_id;
700 if (GTK_IS_BUTTON (child))
701 signal_id = g_signal_lookup ("clicked", GTK_TYPE_BUTTON);
703 signal_id = GTK_WIDGET_GET_CLASS (child)->activate_signal;
709 closure = g_cclosure_new_object (G_CALLBACK (action_widget_activated),
710 G_OBJECT (info_bar));
711 g_signal_connect_closure_by_id (child, signal_id, 0, closure, FALSE);
714 g_warning ("Only 'activatable' widgets can be packed into the action area of a GtkInfoBar");
716 gtk_box_pack_end (GTK_BOX (info_bar->priv->action_area),
717 child, FALSE, FALSE, 0);
718 if (response_id == GTK_RESPONSE_HELP)
719 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (info_bar->priv->action_area),
724 * gtk_info_bar_get_action_area:
725 * @info_bar: a #GtkInfoBar
727 * Returns the action area of @info_bar.
729 * Returns: the action area.
734 ev_info_bar_get_action_area (EvInfoBar *info_bar)
736 g_return_val_if_fail (EV_IS_INFO_BAR (info_bar), NULL);
738 return info_bar->priv->action_area;
742 * gtk_info_bar_get_content_area:
743 * @info_bar: a #GtkInfoBar
745 * Returns the content area of @info_bar.
747 * Returns: the content area.
752 ev_info_bar_get_content_area (EvInfoBar *info_bar)
754 g_return_val_if_fail (EV_IS_INFO_BAR (info_bar), NULL);
756 return info_bar->priv->content_area;
760 * gtk_info_bar_add_button:
761 * @info_bar: a #GtkInfoBar
762 * @button_text: text of button, or stock ID
763 * @response_id: response ID for the button
765 * Adds a button with the given text (or a stock button, if button_text
766 * is a stock ID) and sets things up so that clicking the button will emit
767 * the "response" signal with the given response_id. The button is appended
768 * to the end of the info bars's action area. The button widget is
769 * returned, but usually you don't need it.
771 * Returns: the button widget that was added
776 ev_info_bar_add_button (EvInfoBar *info_bar,
777 const gchar *button_text,
782 g_return_val_if_fail (EV_IS_INFO_BAR (info_bar), NULL);
783 g_return_val_if_fail (button_text != NULL, NULL);
785 button = gtk_button_new_from_stock (button_text);
787 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
789 gtk_widget_show (button);
791 ev_info_bar_add_action_widget (info_bar, button, response_id);
797 add_buttons_valist (EvInfoBar *info_bar,
798 const gchar *first_button_text,
804 g_return_if_fail (EV_IS_INFO_BAR (info_bar));
806 if (first_button_text == NULL)
809 text = first_button_text;
810 response_id = va_arg (args, gint);
814 ev_info_bar_add_button (info_bar, text, response_id);
816 text = va_arg (args, gchar*);
820 response_id = va_arg (args, int);
825 * gtk_info_bar_add_buttons:
826 * @info_bar: a #GtkInfoBar
827 * @first_button_text: button text or stock ID
828 * @...: response ID for first button, then more text-response_id pairs,
831 * Adds more buttons, same as calling gtk_info_bar_add_button()
832 * repeatedly. The variable argument list should be %NULL-terminated
833 * as with gtk_info_bar_new_with_buttons(). Each button must have both
834 * text and response ID.
839 ev_info_bar_add_buttons (EvInfoBar *info_bar,
840 const gchar *first_button_text,
845 va_start (args, first_button_text);
846 add_buttons_valist (info_bar, first_button_text, args);
853 * Creates a new #GtkInfoBar object.
855 * Returns: a new #GtkInfoBar object
860 ev_info_bar_new (void)
862 return g_object_new (EV_TYPE_INFO_BAR, NULL);
866 * gtk_info_bar_new_with_buttons:
867 * @first_button_text: stock ID or text to go in first button, or %NULL
868 * @...: response ID for first button, then additional buttons, ending
871 * Creates a new #GtkInfoBar with buttons. Button text/response ID
872 * pairs should be listed, with a %NULL pointer ending the list.
873 * Button text can be either a stock ID such as %GTK_STOCK_OK, or
874 * some arbitrary text. A response ID can be any positive number,
875 * or one of the values in the #GtkResponseType enumeration. If the
876 * user clicks one of these dialog buttons, GtkInfoBar will emit
877 * the "response" signal with the corresponding response ID.
879 * Returns: a new #GtkInfoBar
882 ev_info_bar_new_with_buttons (const gchar *first_button_text,
888 info_bar = EV_INFO_BAR (ev_info_bar_new ());
890 va_start (args, first_button_text);
891 add_buttons_valist (info_bar, first_button_text, args);
894 return GTK_WIDGET (info_bar);
898 * gtk_info_bar_set_response_sensitive:
899 * @info_bar: a #GtkInfoBar
900 * @response_id: a response ID
901 * @setting: TRUE for sensitive
903 * Calls gtk_widget_set_sensitive (widget, setting) for each
904 * widget in the info bars's action area with the given response_id.
905 * A convenient way to sensitize/desensitize dialog buttons.
910 ev_info_bar_set_response_sensitive (EvInfoBar *info_bar,
914 GList *children, *list;
916 g_return_if_fail (EV_IS_INFO_BAR (info_bar));
918 children = gtk_container_get_children (GTK_CONTAINER (info_bar->priv->action_area));
920 for (list = children; list; list = list->next)
922 GtkWidget *widget = list->data;
923 ResponseData *rd = get_response_data (widget, FALSE);
925 if (rd && rd->response_id == response_id)
926 gtk_widget_set_sensitive (widget, setting);
929 g_list_free (children);
933 * gtk_info_bar_set_default_response:
934 * @info_bar: a #GtkInfoBar
935 * @response_id: a response ID
937 * Sets the last widget in the info bar's action area with
938 * the given response_id as the default widget for the dialog.
939 * Pressing "Enter" normally activates the default widget.
944 ev_info_bar_set_default_response (EvInfoBar *info_bar,
947 GList *children, *list;
949 g_return_if_fail (EV_IS_INFO_BAR (info_bar));
951 children = gtk_container_get_children (GTK_CONTAINER (info_bar->priv->action_area));
953 for (list = children; list; list = list->next)
955 GtkWidget *widget = list->data;
956 ResponseData *rd = get_response_data (widget, FALSE);
958 if (rd && rd->response_id == response_id)
959 gtk_widget_grab_default (widget);
962 g_list_free (children);
966 * gtk_info_bar_response:
967 * @info_bar: a #GtkInfoBar
968 * @response_id: a response ID
970 * Emits the 'response' signal with the given @response_id.
975 ev_info_bar_response (EvInfoBar *info_bar,
978 g_return_if_fail (EV_IS_INFO_BAR (info_bar));
980 g_signal_emit (info_bar, signals[RESPONSE], 0, response_id);
995 } ActionWidgetsSubParserData;
998 attributes_start_element (GMarkupParseContext *context,
999 const gchar *element_name,
1000 const gchar **names,
1001 const gchar **values,
1005 ActionWidgetsSubParserData *parser_data = (ActionWidgetsSubParserData*)user_data;
1008 if (strcmp (element_name, "action-widget") == 0)
1010 for (i = 0; names[i]; i++)
1011 if (strcmp (names[i], "response") == 0)
1012 parser_data->response = g_strdup (values[i]);
1014 else if (strcmp (element_name, "action-widgets") == 0)
1017 g_warning ("Unsupported tag for GtkInfoBar: %s\n", element_name);
1021 attributes_text_element (GMarkupParseContext *context,
1027 ActionWidgetsSubParserData *parser_data = (ActionWidgetsSubParserData*)user_data;
1028 ActionWidgetInfo *item;
1030 if (!parser_data->response)
1033 item = g_new (ActionWidgetInfo, 1);
1034 item->widget_name = g_strndup (text, text_len);
1035 item->response_id = parser_data->response;
1036 parser_data->items = g_slist_prepend (parser_data->items, item);
1037 parser_data->response = NULL;
1040 static const GMarkupParser attributes_parser =
1042 attributes_start_element,
1044 attributes_text_element,
1048 gtk_info_bar_buildable_custom_tag_start (GtkBuildable *buildable,
1049 GtkBuilder *builder,
1051 const gchar *tagname,
1052 GMarkupParser *parser,
1055 ActionWidgetsSubParserData *parser_data;
1060 if (strcmp (tagname, "action-widgets") == 0)
1062 parser_data = g_slice_new0 (ActionWidgetsSubParserData);
1063 parser_data->info_bar = EV_INFO_BAR (buildable);
1064 parser_data->items = NULL;
1066 *parser = attributes_parser;
1067 *data = parser_data;
1071 return parent_buildable_iface->custom_tag_start (buildable, builder, child,
1072 tagname, parser, data);
1076 gtk_info_bar_buildable_custom_finished (GtkBuildable *buildable,
1077 GtkBuilder *builder,
1079 const gchar *tagname,
1083 ActionWidgetsSubParserData *parser_data;
1085 EvInfoBar *info_bar;
1089 if (strcmp (tagname, "action-widgets"))
1091 parent_buildable_iface->custom_finished (buildable, builder, child,
1092 tagname, user_data);
1096 info_bar = EV_INFO_BAR (buildable);
1097 parser_data = (ActionWidgetsSubParserData*)user_data;
1098 parser_data->items = g_slist_reverse (parser_data->items);
1100 for (l = parser_data->items; l; l = l->next)
1102 ActionWidgetInfo *item = l->data;
1104 object = gtk_builder_get_object (builder, item->widget_name);
1107 g_warning ("Unknown object %s specified in action-widgets of %s",
1109 gtk_buildable_get_name (GTK_BUILDABLE (buildable)));
1113 ad = get_response_data (GTK_WIDGET (object), TRUE);
1114 ad->response_id = atoi (item->response_id);
1116 if (GTK_IS_BUTTON (object))
1117 signal_id = g_signal_lookup ("clicked", GTK_TYPE_BUTTON);
1119 signal_id = GTK_WIDGET_GET_CLASS (object)->activate_signal;
1125 closure = g_cclosure_new_object (G_CALLBACK (action_widget_activated),
1126 G_OBJECT (info_bar));
1127 g_signal_connect_closure_by_id (object,
1134 if (ad->response_id == GTK_RESPONSE_HELP)
1135 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (info_bar->priv->action_area),
1136 GTK_WIDGET (object), TRUE);
1138 g_free (item->widget_name);
1139 g_free (item->response_id);
1142 g_slist_free (parser_data->items);
1143 g_slice_free (ActionWidgetsSubParserData, parser_data);
1147 * gtk_info_bar_set_message_type:
1148 * @info_bar: a #GtkInfoBar
1149 * @message_type: a #GtkMessageType
1151 * Sets the message type of the message area.
1152 * GTK+ uses this type to determine what color to use
1153 * when drawing the message area.
1158 ev_info_bar_set_message_type (EvInfoBar *info_bar,
1159 GtkMessageType message_type)
1161 EvInfoBarPrivate *priv;
1164 g_return_if_fail (EV_IS_INFO_BAR (info_bar));
1166 priv = GTK_INFO_BAR_GET_PRIVATE (info_bar);
1168 if (priv->message_type != message_type)
1170 priv->message_type = message_type;
1172 gtk_info_bar_update_colors (info_bar);
1173 gtk_widget_queue_draw (GTK_WIDGET (info_bar));
1175 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (info_bar));
1176 if (GTK_IS_ACCESSIBLE (atk_obj))
1179 const char *stock_id = NULL;
1181 atk_object_set_role (atk_obj, ATK_ROLE_ALERT);
1183 switch (message_type)
1185 case GTK_MESSAGE_INFO:
1186 stock_id = GTK_STOCK_DIALOG_INFO;
1189 case GTK_MESSAGE_QUESTION:
1190 stock_id = GTK_STOCK_DIALOG_QUESTION;
1193 case GTK_MESSAGE_WARNING:
1194 stock_id = GTK_STOCK_DIALOG_WARNING;
1197 case GTK_MESSAGE_ERROR:
1198 stock_id = GTK_STOCK_DIALOG_ERROR;
1201 case GTK_MESSAGE_OTHER:
1205 g_warning ("Unknown GtkMessageType %u", message_type);
1211 gtk_stock_lookup (stock_id, &item);
1212 atk_object_set_name (atk_obj, item.label);
1216 g_object_notify (G_OBJECT (info_bar), "message-type");
1221 * gtk_info_bar_get_message_type:
1222 * @info_bar: a #GtkInfoBar
1224 * Returns the message type of the message area.
1226 * Returns: the message type of the message area.
1231 ev_info_bar_get_message_type (EvInfoBar *info_bar)
1233 EvInfoBarPrivate *priv;
1235 g_return_val_if_fail (EV_IS_INFO_BAR (info_bar), GTK_MESSAGE_OTHER);
1237 priv = GTK_INFO_BAR_GET_PRIVATE (info_bar);
1239 return priv->message_type;
1243 #define __GTK_INFO_BAR_C__