File: pps-form-field.c

package info (click to toggle)
papers 49.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 21,044 kB
  • sloc: ansic: 37,728; sh: 197; xml: 127; makefile: 113
file content (247 lines) | stat: -rw-r--r-- 6,719 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
// SPDX-License-Identifier: GPL-2.0-or-later
/* this file is part of papers, a gnome document viewer
 *
 *  Copyright (C) 2020 Germán Poo-Caamaño <gpoo@gnome.org>
 *  Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
 *  Copyright (C) 2006 Julien Rebetez
 */

#include "pps-form-field.h"
#include "pps-form-field-private.h"
#include <config.h>

typedef struct
{
	gchar *alt_ui_name;
} PpsFormFieldPrivate;

static void pps_form_field_init (PpsFormField *field);
static void pps_form_field_class_init (PpsFormFieldClass *klass);
static void pps_form_field_text_init (PpsFormFieldText *field_text);
static void pps_form_field_text_class_init (PpsFormFieldTextClass *klass);
static void pps_form_field_button_init (PpsFormFieldButton *field_button);
static void pps_form_field_button_class_init (PpsFormFieldButtonClass *klass);
static void pps_form_field_choice_init (PpsFormFieldChoice *field_choice);
static void pps_form_field_choice_class_init (PpsFormFieldChoiceClass *klass);
static void pps_form_field_signature_init (PpsFormFieldSignature *field_choice);
static void pps_form_field_signature_class_init (PpsFormFieldSignatureClass *klass);

G_DEFINE_TYPE (PpsFormFieldText, pps_form_field_text, PPS_TYPE_FORM_FIELD)
G_DEFINE_TYPE (PpsFormFieldButton, pps_form_field_button, PPS_TYPE_FORM_FIELD)
G_DEFINE_TYPE (PpsFormFieldChoice, pps_form_field_choice, PPS_TYPE_FORM_FIELD)
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (PpsFormField, pps_form_field, G_TYPE_OBJECT)
G_DEFINE_TYPE (PpsFormFieldSignature, pps_form_field_signature, PPS_TYPE_FORM_FIELD)

#define GET_FIELD_PRIVATE(o) pps_form_field_get_instance_private (o)
static void
pps_form_field_init (PpsFormField *field)
{
	PpsFormFieldPrivate *priv = GET_FIELD_PRIVATE (field);

	field->page = NULL;
	field->changed = FALSE;
	field->is_read_only = FALSE;
	priv->alt_ui_name = NULL;
}

static void
pps_form_field_finalize (GObject *object)
{
	PpsFormField *field = PPS_FORM_FIELD (object);
	PpsFormFieldPrivate *priv = GET_FIELD_PRIVATE (field);

	g_clear_object (&field->page);
	g_clear_object (&field->activation_link);
	g_clear_pointer (&priv->alt_ui_name, g_free);

	(*G_OBJECT_CLASS (pps_form_field_parent_class)->finalize) (object);
}

static void
pps_form_field_class_init (PpsFormFieldClass *klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS (klass);

	object_class->finalize = pps_form_field_finalize;
}

/**
 * pps_form_field_get_alternate_name
 * @field: a #PpsFormField
 *
 * Gets the alternate ui name of @field. This name is also commonly
 * used by pdf producers/readers to show it as a tooltip when @field area
 * is hovered by a pointing device (eg. mouse).
 *
 * Returns: (transfer full): a string.
 */
gchar *
pps_form_field_get_alternate_name (PpsFormField *field)
{
	PpsFormFieldPrivate *priv;

	g_return_val_if_fail (PPS_IS_FORM_FIELD (field), NULL);

	priv = GET_FIELD_PRIVATE (field);

	return priv->alt_ui_name;
}

/**
 * pps_form_field_set_alternate_name
 * @field: a #PpsFormField
 * @alternative_text: a string with the alternative name of a form field
 *
 * Sets the alternate ui name of @field. This name is also commonly
 * used by pdf producers/readers to show it as a tooltip when @field area
 * is hovered by a pointing device (eg. mouse).
 */
void
pps_form_field_set_alternate_name (PpsFormField *field,
                                   gchar *alternative_text)
{
	PpsFormFieldPrivate *priv;

	g_return_if_fail (PPS_IS_FORM_FIELD (field));

	priv = GET_FIELD_PRIVATE (field);

	if (priv->alt_ui_name)
		g_clear_pointer (&priv->alt_ui_name, g_free);

	priv->alt_ui_name = alternative_text;
}

static void
pps_form_field_text_finalize (GObject *object)
{
	PpsFormFieldText *field_text = PPS_FORM_FIELD_TEXT (object);

	g_clear_pointer (&field_text->text, g_free);

	(*G_OBJECT_CLASS (pps_form_field_text_parent_class)->finalize) (object);
}

static void
pps_form_field_text_init (PpsFormFieldText *field_text)
{
}

static void
pps_form_field_text_class_init (PpsFormFieldTextClass *klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS (klass);

	object_class->finalize = pps_form_field_text_finalize;
}

static void
pps_form_field_button_init (PpsFormFieldButton *field_button)
{
}

static void
pps_form_field_button_class_init (PpsFormFieldButtonClass *klass)
{
}

static void
pps_form_field_choice_finalize (GObject *object)
{
	PpsFormFieldChoice *field_choice = PPS_FORM_FIELD_CHOICE (object);

	g_clear_pointer (&field_choice->selected_items, g_list_free);
	g_clear_pointer (&field_choice->text, g_free);

	(*G_OBJECT_CLASS (pps_form_field_choice_parent_class)->finalize) (object);
}

static void
pps_form_field_choice_init (PpsFormFieldChoice *field_choice)
{
}

static void
pps_form_field_choice_class_init (PpsFormFieldChoiceClass *klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS (klass);

	object_class->finalize = pps_form_field_choice_finalize;
}

static void
pps_form_field_signature_init (PpsFormFieldSignature *field_signature)
{
}

static void
pps_form_field_signature_class_init (PpsFormFieldSignatureClass *klass)
{
}

PpsFormField *
pps_form_field_text_new (gint id,
                         PpsFormFieldTextType type)
{
	PpsFormField *field;

	g_return_val_if_fail (id >= 0, NULL);
	g_return_val_if_fail (type >= PPS_FORM_FIELD_TEXT_NORMAL &&
	                          type <= PPS_FORM_FIELD_TEXT_FILE_SELECT,
	                      NULL);

	field = PPS_FORM_FIELD (g_object_new (PPS_TYPE_FORM_FIELD_TEXT, NULL));
	field->id = id;
	PPS_FORM_FIELD_TEXT (field)->type = type;

	return field;
}

PpsFormField *
pps_form_field_button_new (gint id,
                           PpsFormFieldButtonType type)
{
	PpsFormField *field;

	g_return_val_if_fail (id >= 0, NULL);
	g_return_val_if_fail (type >= PPS_FORM_FIELD_BUTTON_PUSH &&
	                          type <= PPS_FORM_FIELD_BUTTON_RADIO,
	                      NULL);

	field = PPS_FORM_FIELD (g_object_new (PPS_TYPE_FORM_FIELD_BUTTON, NULL));
	field->id = id;
	PPS_FORM_FIELD_BUTTON (field)->type = type;

	return field;
}

PpsFormField *
pps_form_field_choice_new (gint id,
                           PpsFormFieldChoiceType type)
{
	PpsFormField *field;

	g_return_val_if_fail (id >= 0, NULL);
	g_return_val_if_fail (type >= PPS_FORM_FIELD_CHOICE_COMBO &&
	                          type <= PPS_FORM_FIELD_CHOICE_LIST,
	                      NULL);

	field = PPS_FORM_FIELD (g_object_new (PPS_TYPE_FORM_FIELD_CHOICE, NULL));
	field->id = id;
	PPS_FORM_FIELD_CHOICE (field)->type = type;

	return field;
}

PpsFormField *
pps_form_field_signature_new (gint id)
{
	PpsFormField *field;

	g_return_val_if_fail (id >= 0, NULL);

	field = PPS_FORM_FIELD (g_object_new (PPS_TYPE_FORM_FIELD_SIGNATURE, NULL));
	field->id = id;

	return field;
}