~ubuntu-branches/ubuntu/oneiric/evince/oneiric-updates

« back to all changes in this revision

Viewing changes to shell/ev-annotation-properties-dialog.c

  • Committer: Bazaar Package Importer
  • Author(s): Frederic Peters
  • Date: 2011-04-14 16:20:57 UTC
  • mfrom: (1.6.4 upstream)
  • mto: (1.3.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 138.
  • Revision ID: james.westby@ubuntu.com-20110414162057-0ofhbd139zs6ev6y
ImportĀ upstreamĀ versionĀ 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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_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,
 
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
        gtk_dialog_add_buttons (dialog,
 
143
                                GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
 
144
                                GTK_STOCK_APPLY, GTK_RESPONSE_APPLY,
 
145
                                NULL);
 
146
        gtk_dialog_set_default_response (dialog, GTK_RESPONSE_APPLY);
 
147
 
 
148
        content_area = gtk_dialog_get_content_area (dialog);
 
149
        gtk_box_set_spacing (GTK_BOX (content_area), 2);
 
150
 
 
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);
 
158
 
 
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);
 
164
 
 
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,
 
168
                          1, 2, 0, 1,
 
169
                          GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
 
170
        gtk_widget_show (annot_dialog->author);
 
171
 
 
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);
 
177
 
 
178
        annot_dialog->color = gtk_color_button_new_with_color (&color);
 
179
        gtk_table_attach (GTK_TABLE (table), annot_dialog->color,
 
180
                          1, 2, 1, 2,
 
181
                          GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
 
182
        gtk_widget_show (annot_dialog->color);
 
183
 
 
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);
 
189
 
 
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,
 
193
                          1, 2, 2, 3,
 
194
                          GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
 
195
        gtk_widget_show (annot_dialog->opacity);
 
196
 
 
197
        hbox = gtk_hbox_new (FALSE, 6);
 
198
 
 
199
        label = gtk_label_new (NULL);
 
200
        markup = g_strdup_printf ("<small>%s</small>", _("Transparent"));
 
201
        gtk_label_set_markup (GTK_LABEL (label), markup);
 
202
        g_free (markup);
 
203
        gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
 
204
        gtk_widget_show (label);
 
205
 
 
206
        label = gtk_label_new (NULL);
 
207
        markup = g_strdup_printf ("<small>%s</small>", _("Opaque"));
 
208
        gtk_label_set_markup (GTK_LABEL (label), markup);
 
209
        g_free (markup);
 
210
        gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
 
211
        gtk_widget_show (label);
 
212
 
 
213
        gtk_table_attach (GTK_TABLE (table), hbox,
 
214
                          1, 2, 3, 4,
 
215
                          GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
 
216
        gtk_widget_show (hbox);
 
217
 
 
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);
 
223
 
 
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,
 
229
                          1, 2, 4, 5,
 
230
                          GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
 
231
        gtk_widget_show (annot_dialog->popup_state);
 
232
}
 
233
 
 
234
static void
 
235
ev_annotation_properties_dialog_class_init (EvAnnotationPropertiesDialogClass *klass)
 
236
{
 
237
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
238
 
 
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;
 
242
 
 
243
        g_object_class_install_property (object_class,
 
244
                                         PROP_ANNOT_TYPE,
 
245
                                         g_param_spec_enum ("annot-type",
 
246
                                                            "AnnotType",
 
247
                                                            "The type of annotation",
 
248
                                                            EV_TYPE_ANNOTATION_TYPE,
 
249
                                                            EV_ANNOTATION_TYPE_TEXT,
 
250
                                                            G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
 
251
}
 
252
 
 
253
GtkWidget *
 
254
ev_annotation_properties_dialog_new (EvAnnotationType annot_type)
 
255
{
 
256
        return GTK_WIDGET (g_object_new (EV_TYPE_ANNOTATION_PROPERTIES_DIALOG,
 
257
                                         "annot-type", annot_type,
 
258
                                         NULL));
 
259
}
 
260
 
 
261
GtkWidget *
 
262
ev_annotation_properties_dialog_new_with_annotation (EvAnnotation *annot)
 
263
{
 
264
        EvAnnotationPropertiesDialog *dialog;
 
265
        const gchar                  *label;
 
266
        gdouble                       opacity;
 
267
        gboolean                      is_open;
 
268
        GdkColor                      color;
 
269
 
 
270
        dialog = (EvAnnotationPropertiesDialog *)ev_annotation_properties_dialog_new (ev_annotation_get_annotation_type (annot));
 
271
        dialog->annot = g_object_ref (annot);
 
272
 
 
273
        label = ev_annotation_markup_get_label (EV_ANNOTATION_MARKUP (annot));
 
274
        if (label)
 
275
                gtk_entry_set_text (GTK_ENTRY (dialog->author), label);
 
276
 
 
277
        ev_annotation_get_color (annot, &color);
 
278
        gtk_color_button_set_color (GTK_COLOR_BUTTON (dialog->color), &color);
 
279
 
 
280
        opacity = ev_annotation_markup_get_opacity (EV_ANNOTATION_MARKUP (annot));
 
281
        gtk_range_set_value (GTK_RANGE (dialog->opacity), opacity * 100);
 
282
 
 
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),
 
285
                                  is_open ? 0 : 1);
 
286
 
 
287
        if (EV_IS_ANNOTATION_TEXT (annot)) {
 
288
                EvAnnotationText *annot_text = EV_ANNOTATION_TEXT (annot);
 
289
 
 
290
                gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->icon),
 
291
                                          ev_annotation_text_get_icon (annot_text));
 
292
        }
 
293
 
 
294
        return GTK_WIDGET (dialog);
 
295
}
 
296
 
 
297
const gchar *
 
298
ev_annotation_properties_dialog_get_author (EvAnnotationPropertiesDialog *dialog)
 
299
{
 
300
        return gtk_entry_get_text (GTK_ENTRY (dialog->author));
 
301
}
 
302
 
 
303
void
 
304
ev_annotation_properties_dialog_get_color (EvAnnotationPropertiesDialog *dialog,
 
305
                                           GdkColor                     *color)
 
306
{
 
307
        gtk_color_button_get_color (GTK_COLOR_BUTTON (dialog->color), color);
 
308
}
 
309
 
 
310
gdouble
 
311
ev_annotation_properties_dialog_get_opacity (EvAnnotationPropertiesDialog *dialog)
 
312
{
 
313
        return gtk_range_get_value (GTK_RANGE (dialog->opacity)) / 100;
 
314
}
 
315
 
 
316
gboolean
 
317
ev_annotation_properties_dialog_get_popup_is_open (EvAnnotationPropertiesDialog *dialog)
 
318
{
 
319
        return gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->popup_state)) == 0;
 
320
}
 
321
 
 
322
EvAnnotationTextIcon
 
323
ev_annotation_properties_dialog_get_text_icon (EvAnnotationPropertiesDialog *dialog)
 
324
{
 
325
        return gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->icon));
 
326
}