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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
25 #include <gtk/gtkaccessible.h>
26 #include <gtk/gtklabel.h>
27 #include <gtk/gtkhbox.h>
28 #include <gtk/gtkvbox.h>
29 #include <gtk/gtkimage.h>
30 #include <gtk/gtkstock.h>
32 #include "ev-message-area.h"
34 #define EV_MESSAGE_AREA_GET_PRIVATE(obj) \
35 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EV_TYPE_MESSAGE_AREA, EvMessageAreaPrivate))
37 struct _EvMessageAreaPrivate {
40 GtkWidget *secondary_label;
42 guint message_type : 3;
53 static void ev_message_area_set_property (GObject *object,
57 static void ev_message_area_get_property (GObject *object,
62 G_DEFINE_TYPE (EvMessageArea, ev_message_area, GEDIT_TYPE_MESSAGE_AREA)
65 ev_message_area_class_init (EvMessageAreaClass *class)
67 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
69 gobject_class->set_property = ev_message_area_set_property;
70 gobject_class->get_property = ev_message_area_get_property;
72 g_object_class_install_property (gobject_class,
74 g_param_spec_enum ("message-type",
76 "The type of message",
77 GTK_TYPE_MESSAGE_TYPE,
79 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
80 g_object_class_install_property (gobject_class,
82 g_param_spec_string ("text",
84 "The primary text of the message dialog",
87 g_object_class_install_property (gobject_class,
89 g_param_spec_string ("secondary-text",
91 "The secondary text of the message dialog",
94 g_object_class_install_property (gobject_class,
96 g_param_spec_object ("image",
102 g_type_class_add_private (gobject_class, sizeof (EvMessageAreaPrivate));
106 ev_message_area_init (EvMessageArea *area)
108 GtkWidget *hbox, *vbox;
110 area->priv = EV_MESSAGE_AREA_GET_PRIVATE (area);
112 hbox = gtk_hbox_new (FALSE, 12);
113 vbox = gtk_vbox_new (FALSE, 12);
115 area->priv->label = gtk_label_new (NULL);
116 gtk_label_set_use_markup (GTK_LABEL (area->priv->label), TRUE);
117 gtk_label_set_line_wrap (GTK_LABEL (area->priv->label), TRUE);
118 gtk_label_set_selectable (GTK_LABEL (area->priv->label), TRUE);
119 gtk_misc_set_alignment (GTK_MISC (area->priv->label), 0.0, 0.5);
120 GTK_WIDGET_SET_FLAGS (area->priv->label, GTK_CAN_FOCUS);
121 gtk_box_pack_start (GTK_BOX (vbox), area->priv->label, TRUE, TRUE, 0);
122 gtk_widget_show (area->priv->label);
124 area->priv->secondary_label = gtk_label_new (NULL);
125 gtk_label_set_use_markup (GTK_LABEL (area->priv->secondary_label), TRUE);
126 gtk_label_set_line_wrap (GTK_LABEL (area->priv->secondary_label), TRUE);
127 gtk_label_set_selectable (GTK_LABEL (area->priv->secondary_label), TRUE);
128 gtk_misc_set_alignment (GTK_MISC (area->priv->secondary_label), 0.0, 0.5);
129 GTK_WIDGET_SET_FLAGS (area->priv->secondary_label, GTK_CAN_FOCUS);
130 gtk_box_pack_start (GTK_BOX (vbox), area->priv->secondary_label, TRUE, TRUE, 0);
132 area->priv->image = gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG);
133 gtk_misc_set_alignment (GTK_MISC (area->priv->image), 0.5, 0.0);
134 gtk_box_pack_start (GTK_BOX (hbox), area->priv->image, FALSE, FALSE, 0);
135 gtk_widget_show (area->priv->image);
137 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
138 gtk_widget_show (vbox);
140 gedit_message_area_set_contents (GEDIT_MESSAGE_AREA (area), hbox);
141 gtk_widget_show (hbox);
145 ev_message_area_set_image_for_type (EvMessageArea *area,
148 const gchar *stock_id = NULL;
152 case GTK_MESSAGE_INFO:
153 stock_id = GTK_STOCK_DIALOG_INFO;
155 case GTK_MESSAGE_QUESTION:
156 stock_id = GTK_STOCK_DIALOG_QUESTION;
158 case GTK_MESSAGE_WARNING:
159 stock_id = GTK_STOCK_DIALOG_WARNING;
161 case GTK_MESSAGE_ERROR:
162 stock_id = GTK_STOCK_DIALOG_ERROR;
164 case GTK_MESSAGE_OTHER:
167 g_warning ("Unknown GtkMessageType %u", type);
172 gtk_image_set_from_stock (GTK_IMAGE (area->priv->image), stock_id,
173 GTK_ICON_SIZE_DIALOG);
175 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (area));
176 if (GTK_IS_ACCESSIBLE (atk_obj)) {
177 atk_object_set_role (atk_obj, ATK_ROLE_ALERT);
181 gtk_stock_lookup (stock_id, &item);
182 atk_object_set_name (atk_obj, item.label);
188 ev_message_area_set_property (GObject *object,
193 EvMessageArea *area = EV_MESSAGE_AREA (object);
196 case PROP_MESSAGE_TYPE:
197 area->priv->message_type = g_value_get_enum (value);
198 ev_message_area_set_image_for_type (area, area->priv->message_type);
201 ev_message_area_set_text (area, g_value_get_string (value));
203 case PROP_SECONDARY_TEXT:
204 ev_message_area_set_secondary_text (area, g_value_get_string (value));
207 ev_message_area_set_image (area, (GtkWidget *)g_value_get_object (value));
210 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
216 ev_message_area_get_property (GObject *object,
221 EvMessageArea *area = EV_MESSAGE_AREA (object);
224 case PROP_MESSAGE_TYPE:
225 g_value_set_enum (value, (GtkMessageType) area->priv->message_type);
228 g_value_set_string (value, gtk_label_get_label (GTK_LABEL (area->priv->label)));
230 case PROP_SECONDARY_TEXT:
231 g_value_set_string (value, gtk_label_get_label (GTK_LABEL (area->priv->secondary_label)));
234 g_value_set_object (value, area->priv->image);
237 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
243 ev_message_area_new (GtkMessageType type,
245 const gchar *first_button_text,
250 widget = g_object_new (EV_TYPE_MESSAGE_AREA,
251 "message-type", type,
254 if (first_button_text) {
257 va_start (args, first_button_text);
258 gedit_message_area_add_buttons_valist (GEDIT_MESSAGE_AREA (widget),
268 ev_message_area_set_image (EvMessageArea *area,
273 g_return_if_fail (EV_IS_MESSAGE_AREA (area));
275 area->priv->message_type = GTK_MESSAGE_OTHER;
277 parent = area->priv->image->parent;
278 gtk_container_add (GTK_CONTAINER (parent), image);
279 gtk_container_remove (GTK_CONTAINER (parent), area->priv->image);
280 gtk_box_reorder_child (GTK_BOX (parent), image, 0);
282 area->priv->image = image;
284 g_object_notify (G_OBJECT (area), "image");
288 ev_message_area_set_text (EvMessageArea *area,
291 g_return_if_fail (EV_IS_MESSAGE_AREA (area));
296 msg = g_strdup_printf ("<b>%s</b>", str);
297 gtk_label_set_markup (GTK_LABEL (area->priv->label), msg);
300 gtk_label_set_markup (GTK_LABEL (area->priv->label), NULL);
303 g_object_notify (G_OBJECT (area), "text");
307 ev_message_area_set_secondary_text (EvMessageArea *area,
310 g_return_if_fail (EV_IS_MESSAGE_AREA (area));
315 msg = g_strdup_printf ("<small>%s</small>", str);
316 gtk_label_set_markup (GTK_LABEL (area->priv->secondary_label), msg);
318 gtk_widget_show (area->priv->secondary_label);
320 gtk_label_set_markup (GTK_LABEL (area->priv->secondary_label), NULL);
321 gtk_widget_hide (area->priv->secondary_label);
324 g_object_notify (G_OBJECT (area), "secondary-text");