]> www.fi.muni.cz Git - evince.git/blob - shell/ev-annotation-properties-dialog.c
[shell] Dialogues have no separators on gtk 3
[evince.git] / shell / ev-annotation-properties-dialog.c
1 /* ev-annotation-properties-dialog.c
2  *  this file is part of evince, a gnome document viewer
3  *
4  * Copyright (C) 2010 Carlos Garcia Campos  <carlosgc@gnome.org>
5  *
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.
10  *
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.
15  *
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.
19  */
20
21 #include <config.h>
22
23 #include <glib/gi18n.h>
24
25 #include "ev-annotation-properties-dialog.h"
26
27 enum {
28         PROP_0,
29         PROP_ANNOT_TYPE
30 };
31
32 struct _EvAnnotationPropertiesDialog {
33         GtkDialog        base_instance;
34
35         EvAnnotationType annot_type;
36         EvAnnotation    *annot;
37
38         GtkWidget       *table;
39
40         GtkWidget       *author;
41         GtkWidget       *color;
42         GtkWidget       *opacity;
43         GtkWidget       *popup_state;
44
45         /* Text Annotations */
46         GtkWidget       *icon;
47 };
48
49 struct _EvAnnotationPropertiesDialogClass {
50         GtkDialogClass base_class;
51 };
52
53 G_DEFINE_TYPE (EvAnnotationPropertiesDialog, ev_annotation_properties_dialog, GTK_TYPE_DIALOG)
54
55 static void
56 ev_annotation_properties_dialog_dispose (GObject *object)
57 {
58         EvAnnotationPropertiesDialog *dialog = EV_ANNOTATION_PROPERTIES_DIALOG (object);
59
60         if (dialog->annot) {
61                 g_object_unref (dialog->annot);
62                 dialog->annot = NULL;
63         }
64
65         G_OBJECT_CLASS (ev_annotation_properties_dialog_parent_class)->dispose (object);
66 }
67
68 static void
69 ev_annotation_properties_dialog_set_property (GObject      *object,
70                                               guint         prop_id,
71                                               const GValue *value,
72                                               GParamSpec   *pspec)
73 {
74         EvAnnotationPropertiesDialog *dialog = EV_ANNOTATION_PROPERTIES_DIALOG (object);
75
76         switch (prop_id) {
77         case PROP_ANNOT_TYPE:
78                 dialog->annot_type = g_value_get_enum (value);
79                 break;
80         default:
81                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
82         }
83 }
84
85 static void
86 ev_annotation_properties_dialog_constructed (GObject *object)
87 {
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;
91         GtkWidget *label;
92
93         contant_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
94
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);
102
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,
116                                   1, 2, 5, 6,
117                                   GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
118                 gtk_widget_show (dialog->icon);
119
120                 break;
121         case EV_ANNOTATION_TYPE_ATTACHMENT:
122                 /* TODO */
123         default:
124                 break;
125         }
126 }
127
128 static void
129 ev_annotation_properties_dialog_init (EvAnnotationPropertiesDialog *annot_dialog)
130 {
131         GtkDialog *dialog = GTK_DIALOG (annot_dialog);
132         GtkWidget *content_area;
133         GtkWidget *label;
134         GtkWidget *table;
135         GtkWidget *hbox;
136         gchar     *markup;
137         GdkColor   color = { 0, 65535, 65535, 0 };
138
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);
144 #endif
145         gtk_dialog_add_buttons (dialog,
146                                 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
147                                 GTK_STOCK_APPLY, GTK_RESPONSE_APPLY,
148                                 NULL);
149         gtk_dialog_set_default_response (dialog, GTK_RESPONSE_APPLY);
150
151         content_area = gtk_dialog_get_content_area (dialog);
152         gtk_box_set_spacing (GTK_BOX (content_area), 2);
153
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);
161
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);
167
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,
171                           1, 2, 0, 1,
172                           GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
173         gtk_widget_show (annot_dialog->author);
174
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);
180
181         annot_dialog->color = gtk_color_button_new_with_color (&color);
182         gtk_table_attach (GTK_TABLE (table), annot_dialog->color,
183                           1, 2, 1, 2,
184                           GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
185         gtk_widget_show (annot_dialog->color);
186
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);
192
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,
196                           1, 2, 2, 3,
197                           GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
198         gtk_widget_show (annot_dialog->opacity);
199
200         hbox = gtk_hbox_new (FALSE, 6);
201
202         label = gtk_label_new (NULL);
203         markup = g_strdup_printf ("<small>%s</small>", _("Transparent"));
204         gtk_label_set_markup (GTK_LABEL (label), markup);
205         g_free (markup);
206         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
207         gtk_widget_show (label);
208
209         label = gtk_label_new (NULL);
210         markup = g_strdup_printf ("<small>%s</small>", _("Opaque"));
211         gtk_label_set_markup (GTK_LABEL (label), markup);
212         g_free (markup);
213         gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
214         gtk_widget_show (label);
215
216         gtk_table_attach (GTK_TABLE (table), hbox,
217                           1, 2, 3, 4,
218                           GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
219         gtk_widget_show (hbox);
220
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);
226
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,
232                           1, 2, 4, 5,
233                           GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
234         gtk_widget_show (annot_dialog->popup_state);
235 }
236
237 static void
238 ev_annotation_properties_dialog_class_init (EvAnnotationPropertiesDialogClass *klass)
239 {
240         GObjectClass *object_class = G_OBJECT_CLASS (klass);
241
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;
245
246         g_object_class_install_property (object_class,
247                                          PROP_ANNOT_TYPE,
248                                          g_param_spec_enum ("annot-type",
249                                                             "AnnotType",
250                                                             "The type of annotation",
251                                                             EV_TYPE_ANNOTATION_TYPE,
252                                                             EV_ANNOTATION_TYPE_TEXT,
253                                                             G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
254 }
255
256 GtkWidget *
257 ev_annotation_properties_dialog_new (EvAnnotationType annot_type)
258 {
259         return GTK_WIDGET (g_object_new (EV_TYPE_ANNOTATION_PROPERTIES_DIALOG,
260                                          "annot-type", annot_type,
261                                          NULL));
262 }
263
264 GtkWidget *
265 ev_annotation_properties_dialog_new_with_annotation (EvAnnotation *annot)
266 {
267         EvAnnotationPropertiesDialog *dialog;
268         const gchar                  *label;
269         gdouble                       opacity;
270         gboolean                      is_open;
271         GdkColor                      color;
272
273         dialog = (EvAnnotationPropertiesDialog *)ev_annotation_properties_dialog_new (ev_annotation_get_annotation_type (annot));
274         dialog->annot = g_object_ref (annot);
275
276         label = ev_annotation_markup_get_label (EV_ANNOTATION_MARKUP (annot));
277         if (label)
278                 gtk_entry_set_text (GTK_ENTRY (dialog->author), label);
279
280         ev_annotation_get_color (annot, &color);
281         gtk_color_button_set_color (GTK_COLOR_BUTTON (dialog->color), &color);
282
283         opacity = ev_annotation_markup_get_opacity (EV_ANNOTATION_MARKUP (annot));
284         gtk_range_set_value (GTK_RANGE (dialog->opacity), opacity * 100);
285
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),
288                                   is_open ? 0 : 1);
289
290         if (EV_IS_ANNOTATION_TEXT (annot)) {
291                 EvAnnotationText *annot_text = EV_ANNOTATION_TEXT (annot);
292
293                 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->icon),
294                                           ev_annotation_text_get_icon (annot_text));
295         }
296
297         return GTK_WIDGET (dialog);
298 }
299
300 const gchar *
301 ev_annotation_properties_dialog_get_author (EvAnnotationPropertiesDialog *dialog)
302 {
303         return gtk_entry_get_text (GTK_ENTRY (dialog->author));
304 }
305
306 void
307 ev_annotation_properties_dialog_get_color (EvAnnotationPropertiesDialog *dialog,
308                                            GdkColor                     *color)
309 {
310         gtk_color_button_get_color (GTK_COLOR_BUTTON (dialog->color), color);
311 }
312
313 gdouble
314 ev_annotation_properties_dialog_get_opacity (EvAnnotationPropertiesDialog *dialog)
315 {
316         return gtk_range_get_value (GTK_RANGE (dialog->opacity)) / 100;
317 }
318
319 gboolean
320 ev_annotation_properties_dialog_get_popup_is_open (EvAnnotationPropertiesDialog *dialog)
321 {
322         return gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->popup_state)) == 0;
323 }
324
325 EvAnnotationTextIcon
326 ev_annotation_properties_dialog_get_text_icon (EvAnnotationPropertiesDialog *dialog)
327 {
328         return gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->icon));
329 }