1 /* ev-annotation-properties-dialog.c
2 * this file is part of evince, a gnome document viewer
4 * Copyright (C) 2010 Carlos Garcia Campos <carlosgc@gnome.org>
6 * Evince is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Evince is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
23 #include <glib/gi18n.h>
25 #include "ev-annotation-properties-dialog.h"
32 struct _EvAnnotationPropertiesDialog {
33 GtkDialog base_instance;
35 EvAnnotationType annot_type;
43 GtkWidget *popup_state;
45 /* Text Annotations */
49 struct _EvAnnotationPropertiesDialogClass {
50 GtkDialogClass base_class;
53 G_DEFINE_TYPE (EvAnnotationPropertiesDialog, ev_annotation_properties_dialog, GTK_TYPE_DIALOG)
56 ev_annotation_properties_dialog_dispose (GObject *object)
58 EvAnnotationPropertiesDialog *dialog = EV_ANNOTATION_PROPERTIES_DIALOG (object);
61 g_object_unref (dialog->annot);
65 G_OBJECT_CLASS (ev_annotation_properties_dialog_parent_class)->dispose (object);
69 ev_annotation_properties_dialog_set_property (GObject *object,
74 EvAnnotationPropertiesDialog *dialog = EV_ANNOTATION_PROPERTIES_DIALOG (object);
78 dialog->annot_type = g_value_get_enum (value);
81 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
86 ev_annotation_properties_dialog_constructed (GObject *object)
88 EvAnnotationPropertiesDialog *dialog = EV_ANNOTATION_PROPERTIES_DIALOG (object);
89 GtkWidget *contant_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
90 GtkWidget *table = dialog->table;
93 contant_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
95 switch (dialog->annot_type) {
96 case EV_ANNOTATION_TYPE_TEXT:
97 label = gtk_label_new (_("Icon:"));
98 gtk_misc_set_alignment (GTK_MISC (label), 0., 0.5);
99 gtk_table_attach (GTK_TABLE (table), label, 0, 1, 5, 6,
100 GTK_FILL, GTK_FILL, 0, 0);
101 gtk_widget_show (label);
103 dialog->icon = gtk_combo_box_text_new ();
104 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->icon), _("Note"));
105 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->icon), _("Comment"));
106 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->icon), _("Key"));
107 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->icon), _("Help"));
108 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->icon), _("New Paragraph"));
109 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->icon), _("Paragraph"));
110 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->icon), _("Insert"));
111 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->icon), _("Cross"));
112 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->icon), _("Circle"));
113 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->icon), _("Unknown"));
114 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->icon), 0);
115 gtk_table_attach (GTK_TABLE (table), dialog->icon,
117 GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
118 gtk_widget_show (dialog->icon);
121 case EV_ANNOTATION_TYPE_ATTACHMENT:
129 ev_annotation_properties_dialog_init (EvAnnotationPropertiesDialog *annot_dialog)
131 GtkDialog *dialog = GTK_DIALOG (annot_dialog);
132 GtkWidget *content_area;
137 GdkColor color = { 0, 65535, 65535, 0 };
139 gtk_window_set_title (GTK_WINDOW (annot_dialog), _("Annotation Properties"));
140 gtk_window_set_destroy_with_parent (GTK_WINDOW (annot_dialog), TRUE);
141 gtk_container_set_border_width (GTK_CONTAINER (annot_dialog), 5);
142 gtk_dialog_add_buttons (dialog,
143 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
144 GTK_STOCK_APPLY, GTK_RESPONSE_APPLY,
146 gtk_dialog_set_default_response (dialog, GTK_RESPONSE_APPLY);
148 content_area = gtk_dialog_get_content_area (dialog);
149 gtk_box_set_spacing (GTK_BOX (content_area), 2);
151 table = gtk_table_new (5, 2, FALSE);
152 annot_dialog->table = table;
153 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
154 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
155 gtk_container_set_border_width (GTK_CONTAINER (table), 12);
156 gtk_box_pack_start (GTK_BOX (content_area), table, FALSE, FALSE, 0);
157 gtk_widget_show (table);
159 label = gtk_label_new (_("Author:"));
160 gtk_misc_set_alignment (GTK_MISC (label), 0., 0.5);
161 gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
162 GTK_FILL, GTK_FILL, 0, 0);
163 gtk_widget_show (label);
165 annot_dialog->author = gtk_entry_new ();
166 gtk_entry_set_text (GTK_ENTRY (annot_dialog->author), g_get_real_name ());
167 gtk_table_attach (GTK_TABLE (table), annot_dialog->author,
169 GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
170 gtk_widget_show (annot_dialog->author);
172 label = gtk_label_new (_("Color:"));
173 gtk_misc_set_alignment (GTK_MISC (label), 0., 0.5);
174 gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
175 GTK_FILL, GTK_FILL, 0, 0);
176 gtk_widget_show (label);
178 annot_dialog->color = gtk_color_button_new_with_color (&color);
179 gtk_table_attach (GTK_TABLE (table), annot_dialog->color,
181 GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
182 gtk_widget_show (annot_dialog->color);
184 label = gtk_label_new (_("Style:"));
185 gtk_misc_set_alignment (GTK_MISC (label), 0., 0.5);
186 gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3,
187 GTK_FILL, GTK_FILL, 0, 0);
188 gtk_widget_show (label);
190 annot_dialog->opacity = gtk_hscale_new_with_range (0, 100, 5);
191 gtk_range_set_value (GTK_RANGE (annot_dialog->opacity), 100);
192 gtk_table_attach (GTK_TABLE (table), annot_dialog->opacity,
194 GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
195 gtk_widget_show (annot_dialog->opacity);
197 hbox = gtk_hbox_new (FALSE, 6);
199 label = gtk_label_new (NULL);
200 markup = g_strdup_printf ("<small>%s</small>", _("Transparent"));
201 gtk_label_set_markup (GTK_LABEL (label), markup);
203 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
204 gtk_widget_show (label);
206 label = gtk_label_new (NULL);
207 markup = g_strdup_printf ("<small>%s</small>", _("Opaque"));
208 gtk_label_set_markup (GTK_LABEL (label), markup);
210 gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
211 gtk_widget_show (label);
213 gtk_table_attach (GTK_TABLE (table), hbox,
215 GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
216 gtk_widget_show (hbox);
218 label = gtk_label_new (_("Initial window state:"));
219 gtk_misc_set_alignment (GTK_MISC (label), 0., 0.5);
220 gtk_table_attach (GTK_TABLE (table), label, 0, 1, 4, 5,
221 GTK_FILL, GTK_FILL, 0, 0);
222 gtk_widget_show (label);
224 annot_dialog->popup_state = gtk_combo_box_text_new ();
225 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (annot_dialog->popup_state), _("Open"));
226 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (annot_dialog->popup_state), _("Close"));
227 gtk_combo_box_set_active (GTK_COMBO_BOX (annot_dialog->popup_state), 1);
228 gtk_table_attach (GTK_TABLE (table), annot_dialog->popup_state,
230 GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
231 gtk_widget_show (annot_dialog->popup_state);
235 ev_annotation_properties_dialog_class_init (EvAnnotationPropertiesDialogClass *klass)
237 GObjectClass *object_class = G_OBJECT_CLASS (klass);
239 object_class->dispose = ev_annotation_properties_dialog_dispose;
240 object_class->constructed = ev_annotation_properties_dialog_constructed;
241 object_class->set_property = ev_annotation_properties_dialog_set_property;
243 g_object_class_install_property (object_class,
245 g_param_spec_enum ("annot-type",
247 "The type of annotation",
248 EV_TYPE_ANNOTATION_TYPE,
249 EV_ANNOTATION_TYPE_TEXT,
250 G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
254 ev_annotation_properties_dialog_new (EvAnnotationType annot_type)
256 return GTK_WIDGET (g_object_new (EV_TYPE_ANNOTATION_PROPERTIES_DIALOG,
257 "annot-type", annot_type,
262 ev_annotation_properties_dialog_new_with_annotation (EvAnnotation *annot)
264 EvAnnotationPropertiesDialog *dialog;
270 dialog = (EvAnnotationPropertiesDialog *)ev_annotation_properties_dialog_new (ev_annotation_get_annotation_type (annot));
271 dialog->annot = g_object_ref (annot);
273 label = ev_annotation_markup_get_label (EV_ANNOTATION_MARKUP (annot));
275 gtk_entry_set_text (GTK_ENTRY (dialog->author), label);
277 ev_annotation_get_color (annot, &color);
278 gtk_color_button_set_color (GTK_COLOR_BUTTON (dialog->color), &color);
280 opacity = ev_annotation_markup_get_opacity (EV_ANNOTATION_MARKUP (annot));
281 gtk_range_set_value (GTK_RANGE (dialog->opacity), opacity * 100);
283 is_open = ev_annotation_markup_get_popup_is_open (EV_ANNOTATION_MARKUP (annot));
284 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->popup_state),
287 if (EV_IS_ANNOTATION_TEXT (annot)) {
288 EvAnnotationText *annot_text = EV_ANNOTATION_TEXT (annot);
290 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->icon),
291 ev_annotation_text_get_icon (annot_text));
294 return GTK_WIDGET (dialog);
298 ev_annotation_properties_dialog_get_author (EvAnnotationPropertiesDialog *dialog)
300 return gtk_entry_get_text (GTK_ENTRY (dialog->author));
304 ev_annotation_properties_dialog_get_color (EvAnnotationPropertiesDialog *dialog,
307 gtk_color_button_get_color (GTK_COLOR_BUTTON (dialog->color), color);
311 ev_annotation_properties_dialog_get_opacity (EvAnnotationPropertiesDialog *dialog)
313 return gtk_range_get_value (GTK_RANGE (dialog->opacity)) / 100;
317 ev_annotation_properties_dialog_get_popup_is_open (EvAnnotationPropertiesDialog *dialog)
319 return gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->popup_state)) == 0;
323 ev_annotation_properties_dialog_get_text_icon (EvAnnotationPropertiesDialog *dialog)
325 return gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->icon));