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
4 * Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
5 * Copyright (C) 2006 Julien Rebetez
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.
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.
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.
23 #include "ev-form-field.h"
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);
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)
43 ev_form_field_init (EvFormField *field)
46 field->changed = FALSE;
47 field->is_read_only = FALSE;
51 ev_form_field_finalize (GObject *object)
53 EvFormField *field = EV_FORM_FIELD (object);
55 g_object_unref (field->page);
58 (* G_OBJECT_CLASS (ev_form_field_parent_class)->finalize) (object);
62 ev_form_field_class_init (EvFormFieldClass *klass)
64 GObjectClass *object_class = G_OBJECT_CLASS (klass);
66 object_class->finalize = ev_form_field_finalize;
70 ev_form_field_text_finalize (GObject *object)
72 EvFormFieldText *field_text = EV_FORM_FIELD_TEXT (object);
74 if (field_text->text) {
75 g_free (field_text->text);
76 field_text->text = NULL;
79 (* G_OBJECT_CLASS (ev_form_field_text_parent_class)->finalize) (object);
83 ev_form_field_text_init (EvFormFieldText *field_text)
88 ev_form_field_text_class_init (EvFormFieldTextClass *klass)
90 GObjectClass *object_class = G_OBJECT_CLASS (klass);
92 object_class->finalize = ev_form_field_text_finalize;
96 ev_form_field_button_init (EvFormFieldButton *field_button)
101 ev_form_field_button_class_init (EvFormFieldButtonClass *klass)
106 ev_form_field_choice_finalize (GObject *object)
108 EvFormFieldChoice *field_choice = EV_FORM_FIELD_CHOICE (object);
110 if (field_choice->selected_items) {
111 g_list_free (field_choice->selected_items);
112 field_choice->selected_items = NULL;
115 if (field_choice->text) {
116 g_free (field_choice->text);
117 field_choice->text = NULL;
120 (* G_OBJECT_CLASS (ev_form_field_choice_parent_class)->finalize) (object);
124 ev_form_field_choice_init (EvFormFieldChoice *field_choice)
129 ev_form_field_choice_class_init (EvFormFieldChoiceClass *klass)
131 GObjectClass *object_class = G_OBJECT_CLASS (klass);
133 object_class->finalize = ev_form_field_choice_finalize;
137 ev_form_field_signature_init (EvFormFieldSignature *field_signature)
142 ev_form_field_signature_class_init (EvFormFieldSignatureClass *klass)
147 ev_form_field_text_new (gint id,
148 EvFormFieldTextType type)
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);
156 field = EV_FORM_FIELD (g_object_new (EV_TYPE_FORM_FIELD_TEXT, NULL));
158 EV_FORM_FIELD_TEXT (field)->type = type;
164 ev_form_field_button_new (gint id,
165 EvFormFieldButtonType type)
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);
173 field = EV_FORM_FIELD (g_object_new (EV_TYPE_FORM_FIELD_BUTTON, NULL));
175 EV_FORM_FIELD_BUTTON (field)->type = type;
181 ev_form_field_choice_new (gint id,
182 EvFormFieldChoiceType type)
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);
190 field = EV_FORM_FIELD (g_object_new (EV_TYPE_FORM_FIELD_CHOICE, NULL));
192 EV_FORM_FIELD_CHOICE (field)->type = type;
198 ev_form_field_signature_new (gint id)
202 g_return_val_if_fail (id >= 0, NULL);
204 field = EV_FORM_FIELD (g_object_new (EV_TYPE_FORM_FIELD_SIGNATURE, NULL));