gui: New widget PsppireValueEntry for editing a "union value".
[pspp] / src / ui / gui / psppire-value-entry.h
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2012 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifndef PSPPIRE_VALUE_ENTRY_H
18 #define PSPPIRE_VALUE_ENTRY_H 1
19
20 #include <gtk/gtk.h>
21 #include "data/format.h"
22
23 /* PsppireValueEntry is a subclass of GtkComboBoxEntry that is specialized for
24    displaying and entering "union value"s.  Its main advantage over a plain
25    GtkEntry is that, when value labels are supplied, it (optionally) displays
26    the value label instead of the value.  It also allows the user to choose a
27    new value by label from the drop-down list.
28
29    The easiest way to use a PsppireValueEntry is to hand it a particular
30    variable whose values are to be displayed, using
31    psppire_value_entry_set_variable().  If you do that, you don't need any of
32    the other functions to set value labels, format, encoding, width, etc.,
33    because all of those are determined from the variable.  The other functions
34    are useful if no variable is available. */
35
36 G_BEGIN_DECLS
37
38 union value;
39 struct fmt_spec;
40 struct val_labs;
41 struct variable;
42
43 #define PSPPIRE_TYPE_VALUE_ENTRY             (psppire_value_entry_get_type())
44 #define PSPPIRE_VALUE_ENTRY(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj),PSPPIRE_TYPE_VALUE_ENTRY,PsppireValueEntry))
45 #define PSPPIRE_VALUE_ENTRY_CLASS(class)     (G_TYPE_CHECK_CLASS_CAST ((class),PSPPIRE_TYPE_VALUE_ENTRY,PsppireValueEntryClass))
46 #define PSPPIRE_IS_VALUE_ENTRY(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj),PSPPIRE_TYPE_VALUE_ENTRY))
47 #define PSPPIRE_IS_VALUE_ENTRY_CLASS(class)  (G_TYPE_CHECK_CLASS_TYPE ((class),PSPPIRE_TYPE_VALUE_ENTRY))
48 #define PSPPIRE_VALUE_ENTRY_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj),PSPPIRE_TYPE_VALUE_ENTRY,PsppireValueEntryClass))
49
50 typedef struct _PsppireValueEntry      PsppireValueEntry;
51 typedef struct _PsppireValueEntryClass PsppireValueEntryClass;
52
53 struct _PsppireValueEntry {
54   GtkComboBoxEntry parent;
55
56   gboolean show_value_label;
57
58   struct val_labs *val_labs;
59   struct fmt_spec format;
60   gchar *encoding;
61
62   const union value *cur_value;
63 };
64
65 struct _PsppireValueEntryClass {
66   GtkComboBoxEntryClass parent_class;
67 };
68
69 GType psppire_value_entry_get_type (void) G_GNUC_CONST;
70 GtkWidget *psppire_value_entry_new (void);
71
72 void psppire_value_entry_set_show_value_label (PsppireValueEntry *,
73                                                gboolean show_value_label);
74 gboolean psppire_value_entry_get_show_value_label (const PsppireValueEntry *);
75
76 void psppire_value_entry_set_variable (PsppireValueEntry *,
77                                        const struct variable *);
78
79 void psppire_value_entry_set_value_labels (PsppireValueEntry *,
80                                            const struct val_labs *);
81 const struct val_labs *
82 psppire_value_entry_get_value_labels (const PsppireValueEntry *);
83
84 void psppire_value_entry_set_format (PsppireValueEntry *,
85                                      const struct fmt_spec *);
86 const struct fmt_spec *
87 psppire_value_entry_get_format (const PsppireValueEntry *);
88
89 void psppire_value_entry_set_encoding (PsppireValueEntry *, const gchar *);
90 const gchar *psppire_value_entry_get_encoding (const PsppireValueEntry *);
91
92 void psppire_value_entry_set_width (PsppireValueEntry *, int width);
93 int psppire_value_entry_get_width (const PsppireValueEntry *);
94
95 void psppire_value_entry_set_value (PsppireValueEntry *,
96                                     const union value *,
97                                     int width);
98 gboolean psppire_value_entry_get_value (PsppireValueEntry *,
99                                         union value *,
100                                         int width);
101
102 G_END_DECLS
103
104 #endif /* PSPPIRE_VALUE_ENTRY_H */