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_new_text ();
104 gtk_combo_box_append_text (GTK_COMBO_BOX (dialog->icon), _("Note"));
105 gtk_combo_box_append_text (GTK_COMBO_BOX (dialog->icon), _("Comment"));
106 gtk_combo_box_append_text (GTK_COMBO_BOX (dialog->icon), _("Key"));
107 gtk_combo_box_append_text (GTK_COMBO_BOX (dialog->icon), _("Help"));
108 gtk_combo_box_append_text (GTK_COMBO_BOX (dialog->icon), _("New Paragraph"));
109 gtk_combo_box_append_text (GTK_COMBO_BOX (dialog->icon), _("Paragraph"));
110 gtk_combo_box_append_text (GTK_COMBO_BOX (dialog->icon), _("Insert"));
111 gtk_combo_box_append_text (GTK_COMBO_BOX (dialog->icon), _("Cross"));
112 gtk_combo_box_append_text (GTK_COMBO_BOX (dialog->icon), _("Circle"));
113 gtk_combo_box_append_text (GTK_COMBO_BOX (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 #if !GTK_CHECK_VERSION (2, 90, 7)
143 gtk_dialog_set_has_separator (dialog, FALSE);
145 gtk_dialog_add_buttons (dialog,
146 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
147 GTK_STOCK_APPLY, GTK_RESPONSE_APPLY,
149 gtk_dialog_set_default_response (dialog, GTK_RESPONSE_APPLY);
151 content_area = gtk_dialog_get_content_area (dialog);
152 gtk_box_set_spacing (GTK_BOX (content_area), 2);
154 table = gtk_table_new (5, 2, FALSE);
155 annot_dialog->table = table;
156 gtk_table_set_col_spacings (GTK_TABLE (table), 12);
157 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
158 gtk_container_set_border_width (GTK_CONTAINER (table), 12);
159 gtk_box_pack_start (GTK_BOX (content_area), table, FALSE, FALSE, 0);
160 gtk_widget_show (table);
162 label = gtk_label_new (_("Author:"));
163 gtk_misc_set_alignment (GTK_MISC (label), 0., 0.5);
164 gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
165 GTK_FILL, GTK_FILL, 0, 0);
166 gtk_widget_show (label);
168 annot_dialog->author = gtk_entry_new ();
169 gtk_entry_set_text (GTK_ENTRY (annot_dialog->author), g_get_real_name ());
170 gtk_table_attach (GTK_TABLE (table), annot_dialog->author,
172 GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
173 gtk_widget_show (annot_dialog->author);
175 label = gtk_label_new (_("Color:"));
176 gtk_misc_set_alignment (GTK_MISC (label), 0., 0.5);
177 gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
178 GTK_FILL, GTK_FILL, 0, 0);
179 gtk_widget_show (label);
181 annot_dialog->color = gtk_color_button_new_with_color (&color);
182 gtk_table_attach (GTK_TABLE (table), annot_dialog->color,
184 GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
185 gtk_widget_show (annot_dialog->color);
187 label = gtk_label_new (_("Style:"));
188 gtk_misc_set_alignment (GTK_MISC (label), 0., 0.5);
189 gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3,
190 GTK_FILL, GTK_FILL, 0, 0);
191 gtk_widget_show (label);
193 annot_dialog->opacity = gtk_hscale_new_with_range (0, 100, 5);
194 gtk_range_set_value (GTK_RANGE (annot_dialog->opacity), 100);
195 gtk_table_attach (GTK_TABLE (table), annot_dialog->opacity,
197 GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
198 gtk_widget_show (annot_dialog->opacity);
200 hbox = gtk_hbox_new (FALSE, 6);
202 label = gtk_label_new (NULL);
203 markup = g_strdup_printf ("<small>%s</small>", _("Transparent"));
204 gtk_label_set_markup (GTK_LABEL (label), markup);
206 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
207 gtk_widget_show (label);
209 label = gtk_label_new (NULL);
210 markup = g_strdup_printf ("<small>%s</small>", _("Opaque"));
211 gtk_label_set_markup (GTK_LABEL (label), markup);
213 gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
214 gtk_widget_show (label);
216 gtk_table_attach (GTK_TABLE (table), hbox,
218 GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
219 gtk_widget_show (hbox);
221 label = gtk_label_new (_("Initial window state:"));
222 gtk_misc_set_alignment (GTK_MISC (label), 0., 0.5);
223 gtk_table_attach (GTK_TABLE (table), label, 0, 1, 4, 5,
224 GTK_FILL, GTK_FILL, 0, 0);
225 gtk_widget_show (label);
227 annot_dialog->popup_state = gtk_combo_box_new_text ();
228 gtk_combo_box_append_text (GTK_COMBO_BOX (annot_dialog->popup_state), _("Open"));
229 gtk_combo_box_append_text (GTK_COMBO_BOX (annot_dialog->popup_state), _("Close"));
230 gtk_combo_box_set_active (GTK_COMBO_BOX (annot_dialog->popup_state), 1);
231 gtk_table_attach (GTK_TABLE (table), annot_dialog->popup_state,
233 GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
234 gtk_widget_show (annot_dialog->popup_state);
238 ev_annotation_properties_dialog_class_init (EvAnnotationPropertiesDialogClass *klass)
240 GObjectClass *object_class = G_OBJECT_CLASS (klass);
242 object_class->dispose = ev_annotation_properties_dialog_dispose;
243 object_class->constructed = ev_annotation_properties_dialog_constructed;
244 object_class->set_property = ev_annotation_properties_dialog_set_property;
246 g_object_class_install_property (object_class,
248 g_param_spec_enum ("annot-type",
250 "The type of annotation",
251 EV_TYPE_ANNOTATION_TYPE,
252 EV_ANNOTATION_TYPE_TEXT,
253 G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
257 ev_annotation_properties_dialog_new (EvAnnotationType annot_type)
259 return GTK_WIDGET (g_object_new (EV_TYPE_ANNOTATION_PROPERTIES_DIALOG,
260 "annot-type", annot_type,
265 ev_annotation_properties_dialog_new_with_annotation (EvAnnotation *annot)
267 EvAnnotationPropertiesDialog *dialog;
273 dialog = (EvAnnotationPropertiesDialog *)ev_annotation_properties_dialog_new (ev_annotation_get_annotation_type (annot));
274 dialog->annot = g_object_ref (annot);
276 label = ev_annotation_markup_get_label (EV_ANNOTATION_MARKUP (annot));
278 gtk_entry_set_text (GTK_ENTRY (dialog->author), label);
280 ev_annotation_get_color (annot, &color);
281 gtk_color_button_set_color (GTK_COLOR_BUTTON (dialog->color), &color);
283 opacity = ev_annotation_markup_get_opacity (EV_ANNOTATION_MARKUP (annot));
284 gtk_range_set_value (GTK_RANGE (dialog->opacity), opacity * 100);
286 is_open = ev_annotation_markup_get_popup_is_open (EV_ANNOTATION_MARKUP (annot));
287 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->popup_state),
290 if (EV_IS_ANNOTATION_TEXT (annot)) {
291 EvAnnotationText *annot_text = EV_ANNOTATION_TEXT (annot);
293 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->icon),
294 ev_annotation_text_get_icon (annot_text));
297 return GTK_WIDGET (dialog);
301 ev_annotation_properties_dialog_get_author (EvAnnotationPropertiesDialog *dialog)
303 return gtk_entry_get_text (GTK_ENTRY (dialog->author));
307 ev_annotation_properties_dialog_get_color (EvAnnotationPropertiesDialog *dialog,
310 gtk_color_button_get_color (GTK_COLOR_BUTTON (dialog->color), color);
314 ev_annotation_properties_dialog_get_opacity (EvAnnotationPropertiesDialog *dialog)
316 return gtk_range_get_value (GTK_RANGE (dialog->opacity)) / 100;
320 ev_annotation_properties_dialog_get_popup_is_open (EvAnnotationPropertiesDialog *dialog)
322 return gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->popup_state)) == 0;
326 ev_annotation_properties_dialog_get_text_icon (EvAnnotationPropertiesDialog *dialog)
328 return gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->icon));