]> www.fi.muni.cz Git - evince.git/blob - libdocument/ev-form-field.c
Replace mkdtemp() with _ev_g_mkdtemp().
[evince.git] / libdocument / ev-form-field.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /* this file is part of evince, a gnome document viewer
3  *
4  *  Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
5  *  Copyright (C) 2006 Julien Rebetez
6  *
7  * Evince is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * Evince is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
20  */
21
22 #include <config.h>
23 #include "ev-form-field.h"
24
25 static void ev_form_field_init                 (EvFormField               *field);
26 static void ev_form_field_class_init           (EvFormFieldClass          *klass);
27 static void ev_form_field_text_init            (EvFormFieldText           *field_text);
28 static void ev_form_field_text_class_init      (EvFormFieldTextClass      *klass);
29 static void ev_form_field_button_init          (EvFormFieldButton         *field_button);
30 static void ev_form_field_button_class_init    (EvFormFieldButtonClass    *klass);
31 static void ev_form_field_choice_init          (EvFormFieldChoice         *field_choice);
32 static void ev_form_field_choice_class_init    (EvFormFieldChoiceClass    *klass);
33 static void ev_form_field_signature_init       (EvFormFieldSignature      *field_choice);
34 static void ev_form_field_signature_class_init (EvFormFieldSignatureClass *klass);
35
36 G_DEFINE_ABSTRACT_TYPE (EvFormField, ev_form_field, G_TYPE_OBJECT)
37 G_DEFINE_TYPE (EvFormFieldText, ev_form_field_text, EV_TYPE_FORM_FIELD)
38 G_DEFINE_TYPE (EvFormFieldButton, ev_form_field_button, EV_TYPE_FORM_FIELD)
39 G_DEFINE_TYPE (EvFormFieldChoice, ev_form_field_choice, EV_TYPE_FORM_FIELD)
40 G_DEFINE_TYPE (EvFormFieldSignature, ev_form_field_signature, EV_TYPE_FORM_FIELD)
41
42 static void
43 ev_form_field_init (EvFormField *field)
44 {
45         field->page = NULL;
46         field->changed = FALSE;
47         field->is_read_only = FALSE;
48 }
49
50 static void
51 ev_form_field_finalize (GObject *object)
52 {
53         EvFormField *field = EV_FORM_FIELD (object);
54
55         g_object_unref (field->page);
56         field->page = NULL;
57
58         (* G_OBJECT_CLASS (ev_form_field_parent_class)->finalize) (object);
59 }
60
61 static void
62 ev_form_field_class_init (EvFormFieldClass *klass)
63 {
64         GObjectClass *object_class = G_OBJECT_CLASS (klass);
65
66         object_class->finalize = ev_form_field_finalize;
67 }
68
69 static void
70 ev_form_field_text_finalize (GObject *object)
71 {
72         EvFormFieldText *field_text = EV_FORM_FIELD_TEXT (object);
73
74         if (field_text->text) {
75                 g_free (field_text->text);
76                 field_text->text = NULL;
77         }
78
79         (* G_OBJECT_CLASS (ev_form_field_text_parent_class)->finalize) (object);
80 }
81
82 static void
83 ev_form_field_text_init (EvFormFieldText *field_text)
84 {
85 }
86
87 static void
88 ev_form_field_text_class_init (EvFormFieldTextClass *klass)
89 {
90         GObjectClass *object_class = G_OBJECT_CLASS (klass);
91
92         object_class->finalize = ev_form_field_text_finalize;
93 }
94
95 static void
96 ev_form_field_button_init (EvFormFieldButton *field_button)
97 {
98 }
99
100 static void
101 ev_form_field_button_class_init (EvFormFieldButtonClass *klass)
102 {
103 }
104
105 static void
106 ev_form_field_choice_finalize (GObject *object)
107 {
108         EvFormFieldChoice *field_choice = EV_FORM_FIELD_CHOICE (object);
109
110         if (field_choice->selected_items) {
111                 g_list_free (field_choice->selected_items);
112                 field_choice->selected_items = NULL;
113         }
114
115         if (field_choice->text) {
116                 g_free (field_choice->text);
117                 field_choice->text = NULL;
118         }
119
120         (* G_OBJECT_CLASS (ev_form_field_choice_parent_class)->finalize) (object);
121 }
122
123 static void
124 ev_form_field_choice_init (EvFormFieldChoice *field_choice)
125 {
126 }
127
128 static void
129 ev_form_field_choice_class_init (EvFormFieldChoiceClass *klass)
130 {
131         GObjectClass *object_class = G_OBJECT_CLASS (klass);
132
133         object_class->finalize = ev_form_field_choice_finalize;
134 }
135
136 static void
137 ev_form_field_signature_init (EvFormFieldSignature *field_signature)
138 {
139 }
140
141 static void
142 ev_form_field_signature_class_init (EvFormFieldSignatureClass *klass)
143 {
144 }
145
146 EvFormField *
147 ev_form_field_text_new (gint                id,
148                         EvFormFieldTextType type)
149 {
150         EvFormField *field;
151         
152         g_return_val_if_fail (id >= 0, NULL);
153         g_return_val_if_fail (type >= EV_FORM_FIELD_TEXT_NORMAL &&
154                               type <= EV_FORM_FIELD_TEXT_FILE_SELECT, NULL);
155
156         field = EV_FORM_FIELD (g_object_new (EV_TYPE_FORM_FIELD_TEXT, NULL));
157         field->id = id;
158         EV_FORM_FIELD_TEXT (field)->type = type;
159
160         return field;
161 }
162
163 EvFormField *
164 ev_form_field_button_new (gint                  id,
165                           EvFormFieldButtonType type)
166 {
167         EvFormField *field;
168
169         g_return_val_if_fail (id >= 0, NULL);
170         g_return_val_if_fail (type >= EV_FORM_FIELD_BUTTON_PUSH &&
171                               type <= EV_FORM_FIELD_BUTTON_RADIO, NULL);
172
173         field = EV_FORM_FIELD (g_object_new (EV_TYPE_FORM_FIELD_BUTTON, NULL));
174         field->id = id;
175         EV_FORM_FIELD_BUTTON (field)->type = type;
176
177         return field;
178 }
179
180 EvFormField *
181 ev_form_field_choice_new (gint                  id,
182                           EvFormFieldChoiceType type)
183 {
184         EvFormField *field;
185
186         g_return_val_if_fail (id >= 0, NULL);
187         g_return_val_if_fail (type >= EV_FORM_FIELD_CHOICE_COMBO &&
188                               type <= EV_FORM_FIELD_CHOICE_LIST, NULL);
189         
190         field = EV_FORM_FIELD (g_object_new (EV_TYPE_FORM_FIELD_CHOICE, NULL));
191         field->id = id;
192         EV_FORM_FIELD_CHOICE (field)->type = type;
193
194         return field;
195 }
196
197 EvFormField *
198 ev_form_field_signature_new (gint id)
199 {
200         EvFormField *field;
201
202         g_return_val_if_fail (id >= 0, NULL);
203
204         field = EV_FORM_FIELD (g_object_new (EV_TYPE_FORM_FIELD_SIGNATURE, NULL));
205         field->id = id;
206
207         return field;
208 }
209