2 * this file is part of evince, a gnome document viewer
4 * Copyright (C) 2007 Carlos Garcia Campos
7 * Carlos Garcia Campos <carlosgc@gnome.org>
9 * Evince is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * Evince is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #include "ev-message-area.h"
28 #define EV_MESSAGE_AREA_GET_PRIVATE(obj) \
29 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EV_TYPE_MESSAGE_AREA, EvMessageAreaPrivate))
31 struct _EvMessageAreaPrivate {
35 GtkWidget *secondary_label;
37 guint message_type : 3;
47 static void ev_message_area_set_property (GObject *object,
51 static void ev_message_area_get_property (GObject *object,
56 G_DEFINE_TYPE (EvMessageArea, ev_message_area, GTK_TYPE_INFO_BAR)
59 ev_message_area_class_init (EvMessageAreaClass *class)
61 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
63 gobject_class->set_property = ev_message_area_set_property;
64 gobject_class->get_property = ev_message_area_get_property;
66 g_object_class_install_property (gobject_class,
68 g_param_spec_string ("text",
70 "The primary text of the message dialog",
73 g_object_class_install_property (gobject_class,
75 g_param_spec_string ("secondary-text",
77 "The secondary text of the message dialog",
80 g_object_class_install_property (gobject_class,
82 g_param_spec_object ("image",
88 g_type_class_add_private (gobject_class, sizeof (EvMessageAreaPrivate));
92 ev_message_area_init (EvMessageArea *area)
94 GtkWidget *hbox, *vbox;
95 GtkWidget *content_area;
97 area->priv = EV_MESSAGE_AREA_GET_PRIVATE (area);
99 area->priv->main_box = gtk_vbox_new (FALSE, 12);
101 hbox = gtk_hbox_new (FALSE, 12);
102 vbox = gtk_vbox_new (FALSE, 12);
104 area->priv->label = gtk_label_new (NULL);
105 gtk_label_set_use_markup (GTK_LABEL (area->priv->label), TRUE);
106 gtk_label_set_line_wrap (GTK_LABEL (area->priv->label), TRUE);
107 gtk_label_set_selectable (GTK_LABEL (area->priv->label), TRUE);
108 gtk_misc_set_alignment (GTK_MISC (area->priv->label), 0.0, 0.5);
109 gtk_widget_set_can_focus (area->priv->label, TRUE);
110 gtk_box_pack_start (GTK_BOX (vbox), area->priv->label, TRUE, TRUE, 0);
111 gtk_widget_show (area->priv->label);
113 area->priv->secondary_label = gtk_label_new (NULL);
114 gtk_label_set_use_markup (GTK_LABEL (area->priv->secondary_label), TRUE);
115 gtk_label_set_line_wrap (GTK_LABEL (area->priv->secondary_label), TRUE);
116 gtk_label_set_selectable (GTK_LABEL (area->priv->secondary_label), TRUE);
117 gtk_misc_set_alignment (GTK_MISC (area->priv->secondary_label), 0.0, 0.5);
118 gtk_widget_set_can_focus (area->priv->secondary_label, TRUE);
119 gtk_box_pack_start (GTK_BOX (vbox), area->priv->secondary_label, TRUE, TRUE, 0);
121 area->priv->image = gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG);
122 gtk_misc_set_alignment (GTK_MISC (area->priv->image), 0.5, 0.0);
123 gtk_box_pack_start (GTK_BOX (hbox), area->priv->image, FALSE, FALSE, 0);
124 gtk_widget_show (area->priv->image);
126 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
127 gtk_widget_show (vbox);
129 gtk_box_pack_start (GTK_BOX (area->priv->main_box), hbox, TRUE, TRUE, 0);
130 gtk_widget_show (hbox);
132 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (area));
133 gtk_container_add (GTK_CONTAINER (content_area), area->priv->main_box);
134 gtk_widget_show (area->priv->main_box);
138 ev_message_area_set_image_for_type (EvMessageArea *area,
141 const gchar *stock_id = NULL;
145 case GTK_MESSAGE_INFO:
146 stock_id = GTK_STOCK_DIALOG_INFO;
148 case GTK_MESSAGE_QUESTION:
149 stock_id = GTK_STOCK_DIALOG_QUESTION;
151 case GTK_MESSAGE_WARNING:
152 stock_id = GTK_STOCK_DIALOG_WARNING;
154 case GTK_MESSAGE_ERROR:
155 stock_id = GTK_STOCK_DIALOG_ERROR;
157 case GTK_MESSAGE_OTHER:
160 g_warning ("Unknown GtkMessageType %u", type);
165 gtk_image_set_from_stock (GTK_IMAGE (area->priv->image), stock_id,
166 GTK_ICON_SIZE_DIALOG);
168 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (area));
169 if (GTK_IS_ACCESSIBLE (atk_obj)) {
170 atk_object_set_role (atk_obj, ATK_ROLE_ALERT);
174 gtk_stock_lookup (stock_id, &item);
175 atk_object_set_name (atk_obj, item.label);
181 ev_message_area_set_property (GObject *object,
186 EvMessageArea *area = EV_MESSAGE_AREA (object);
190 ev_message_area_set_text (area, g_value_get_string (value));
192 case PROP_SECONDARY_TEXT:
193 ev_message_area_set_secondary_text (area, g_value_get_string (value));
196 ev_message_area_set_image (area, (GtkWidget *)g_value_get_object (value));
199 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
205 ev_message_area_get_property (GObject *object,
210 EvMessageArea *area = EV_MESSAGE_AREA (object);
214 g_value_set_string (value, gtk_label_get_label (GTK_LABEL (area->priv->label)));
216 case PROP_SECONDARY_TEXT:
217 g_value_set_string (value, gtk_label_get_label (GTK_LABEL (area->priv->secondary_label)));
220 g_value_set_object (value, area->priv->image);
223 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
229 _ev_message_area_add_buttons_valist (EvMessageArea *area,
230 const gchar *first_button_text,
236 if (first_button_text == NULL)
239 text = first_button_text;
240 response_id = va_arg (args, gint);
242 while (text != NULL) {
243 gtk_info_bar_add_button (GTK_INFO_BAR (area), text, response_id);
245 text = va_arg (args, gchar*);
249 response_id = va_arg (args, int);
254 _ev_message_area_get_main_box (EvMessageArea *area)
256 return area->priv->main_box;
260 ev_message_area_new (GtkMessageType type,
262 const gchar *first_button_text,
267 widget = g_object_new (EV_TYPE_MESSAGE_AREA,
268 "message-type", type,
271 ev_message_area_set_image_for_type (EV_MESSAGE_AREA (widget), type);
272 if (first_button_text) {
275 va_start (args, first_button_text);
276 _ev_message_area_add_buttons_valist (EV_MESSAGE_AREA (widget),
277 first_button_text, args);
285 ev_message_area_set_image (EvMessageArea *area,
290 g_return_if_fail (EV_IS_MESSAGE_AREA (area));
292 area->priv->message_type = GTK_MESSAGE_OTHER;
294 parent = gtk_widget_get_parent (area->priv->image);
295 gtk_container_add (GTK_CONTAINER (parent), image);
296 gtk_container_remove (GTK_CONTAINER (parent), area->priv->image);
297 gtk_box_reorder_child (GTK_BOX (parent), image, 0);
299 area->priv->image = image;
301 g_object_notify (G_OBJECT (area), "image");
305 ev_message_area_set_image_from_stock (EvMessageArea *area,
306 const gchar *stock_id)
308 g_return_if_fail (EV_IS_MESSAGE_AREA (area));
309 g_return_if_fail (stock_id != NULL);
311 gtk_image_set_from_stock (GTK_IMAGE (area->priv->image),
313 GTK_ICON_SIZE_DIALOG);
317 ev_message_area_set_text (EvMessageArea *area,
320 g_return_if_fail (EV_IS_MESSAGE_AREA (area));
325 msg = g_strdup_printf ("<b>%s</b>", str);
326 gtk_label_set_markup (GTK_LABEL (area->priv->label), msg);
329 gtk_label_set_markup (GTK_LABEL (area->priv->label), NULL);
332 g_object_notify (G_OBJECT (area), "text");
336 ev_message_area_set_secondary_text (EvMessageArea *area,
339 g_return_if_fail (EV_IS_MESSAGE_AREA (area));
344 msg = g_strdup_printf ("<small>%s</small>", str);
345 gtk_label_set_markup (GTK_LABEL (area->priv->secondary_label), msg);
347 gtk_widget_show (area->priv->secondary_label);
349 gtk_label_set_markup (GTK_LABEL (area->priv->secondary_label), NULL);
350 gtk_widget_hide (area->priv->secondary_label);
353 g_object_notify (G_OBJECT (area), "secondary-text");