1
/********************************************************************\
2
* recncell.c -- reconcile checkbox cell *
4
* This program is free software; you can redistribute it and/or *
5
* modify it under the terms of the GNU General Public License as *
6
* published by the Free Software Foundation; either version 2 of *
7
* the License, or (at your option) any later version. *
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. *
14
* You should have received a copy of the GNU General Public License*
15
* along with this program; if not, contact: *
17
* Free Software Foundation Voice: +1-617-542-5942 *
18
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
19
* Boston, MA 02110-1301, USA gnu@gnu.org *
21
\********************************************************************/
28
* Implements a mouse-click cell that allows a series
29
* of values to be clicked through.
32
* Copyright (c) 1998 Linas Vepstas
33
* Copyright (c) 2000 Dave Peticolas
34
* Copyright (c) 2001 Derek Atkins
43
#include "basiccell.h"
44
#include "gnc-engine.h"
48
static void gnc_recn_cell_set_value (BasicCell *_cell, const char *value);
52
gnc_recn_cell_get_string (RecnCell *cell, char flag)
54
static char str[2] = { 0, 0 };
56
if (cell->get_string != NULL)
57
return (cell->get_string)(flag);
65
gnc_recn_cell_enter (BasicCell *_cell,
70
RecnCell *cell = (RecnCell *) _cell;
73
if (cell->confirm_cb &&
74
! (cell->confirm_cb (cell->flag, cell->confirm_data)))
77
/* Find the current flag in the list of flags */
78
this_flag = strchr (cell->flag_order, cell->flag);
80
if (this_flag == NULL || *this_flag == '\0') {
81
/* If it's not there (or the list is empty) use default_flag */
82
cell->flag = cell->default_flag;
85
/* It is in the list -- choose the -next- item in the list (wrapping
86
* around as necessary).
89
if (*this_flag != '\0')
90
cell->flag = *this_flag;
92
cell->flag = *(cell->flag_order);
95
/* And set the display */
96
gnc_recn_cell_set_flag (cell, cell->flag);
102
gnc_recn_cell_init (RecnCell *cell)
104
gnc_basic_cell_init (&cell->cell);
106
gnc_recn_cell_set_flag (cell, '\0');
107
cell->confirm_cb = NULL;
108
cell->get_string = NULL;
109
cell->valid_flags = "";
110
cell->flag_order = "";
112
cell->cell.enter_cell = gnc_recn_cell_enter;
113
cell->cell.set_value = gnc_recn_cell_set_value;
117
gnc_recn_cell_new (void)
121
cell = g_new0 (RecnCell, 1);
123
gnc_recn_cell_init (cell);
128
/* assumes we are given the untranslated form */
130
gnc_recn_cell_set_value (BasicCell *_cell, const char *value)
132
RecnCell *cell = (RecnCell *) _cell;
135
if (!value || *value == '\0')
137
cell->flag = cell->default_flag;
138
gnc_basic_cell_set_value_internal (_cell, "");
142
flag = cell->default_flag;
143
if (strchr (cell->valid_flags, *value) != NULL)
146
gnc_recn_cell_set_flag (cell, flag);
150
gnc_recn_cell_set_flag (RecnCell *cell, char flag)
154
g_return_if_fail (cell != NULL);
157
string = gnc_recn_cell_get_string (cell, flag);
159
gnc_basic_cell_set_value_internal (&cell->cell, string);
163
gnc_recn_cell_get_flag (RecnCell *cell)
165
g_return_val_if_fail (cell != NULL, '\0');
171
gnc_recn_cell_set_string_getter (RecnCell *cell,
172
RecnCellStringGetter get_string)
174
g_return_if_fail (cell != NULL);
175
cell->get_string = get_string;
179
gnc_recn_cell_set_confirm_cb (RecnCell *cell, RecnCellConfirm confirm_cb,
182
g_return_if_fail (cell != NULL);
184
cell->confirm_cb = confirm_cb;
185
cell->confirm_data = data;
189
gnc_recn_cell_set_valid_flags (RecnCell *cell, const char *flags,
192
g_return_if_fail (cell != NULL);
193
g_return_if_fail (flags != NULL);
195
cell->valid_flags = (char *)flags;
196
cell->default_flag = default_flag;
200
gnc_recn_cell_set_flag_order (RecnCell *cell, const char *flags)
202
g_return_if_fail (cell != NULL);
203
g_return_if_fail (flags != NULL);
205
cell->flag_order = (char *)flags;