~siretart/gnucash/ubuntu-fullsource

« back to all changes in this revision

Viewing changes to src/register/register-core/recncell.c

  • Committer: Reinhard Tartler
  • Date: 2008-08-03 07:25:46 UTC
  • Revision ID: siretart@tauware.de-20080803072546-y6p8xda8zpfi62ys
import gnucash_2.2.4.orig.tar.gz

The original tarball had the md5sum: 27e660297dc5b8ce574515779d05a5a5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/********************************************************************\
 
2
 * recncell.c -- reconcile checkbox cell                            *
 
3
 *                                                                  *
 
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.              *
 
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, contact:                        *
 
16
 *                                                                  *
 
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                   *
 
20
 *                                                                  *
 
21
\********************************************************************/
 
22
 
 
23
/*
 
24
 * FILE:
 
25
 * recncell.c
 
26
 * 
 
27
 * FUNCTION:
 
28
 * Implements a mouse-click cell that allows a series
 
29
 * of values to be clicked through.
 
30
 *
 
31
 * HISTORY:
 
32
 * Copyright (c) 1998 Linas Vepstas
 
33
 * Copyright (c) 2000 Dave Peticolas
 
34
 * Copyright (c) 2001 Derek Atkins
 
35
 */
 
36
 
 
37
#include "config.h"
 
38
 
 
39
#include <stdlib.h>
 
40
#include <string.h>
 
41
#include <time.h>
 
42
 
 
43
#include "basiccell.h"
 
44
#include "gnc-engine.h"
 
45
#include "recncell.h"
 
46
 
 
47
 
 
48
static void gnc_recn_cell_set_value (BasicCell *_cell, const char *value);
 
49
 
 
50
 
 
51
static const char *
 
52
gnc_recn_cell_get_string (RecnCell *cell, char flag)
 
53
{
 
54
  static char str[2] = { 0, 0 };
 
55
 
 
56
  if (cell->get_string != NULL)
 
57
    return (cell->get_string)(flag);
 
58
 
 
59
  str[0] = flag;
 
60
 
 
61
  return str;
 
62
}
 
63
 
 
64
static gboolean
 
65
gnc_recn_cell_enter (BasicCell *_cell,
 
66
                     int *cursor_position,
 
67
                     int *start_selection,
 
68
                     int *end_selection)
 
69
{
 
70
  RecnCell *cell = (RecnCell *) _cell;
 
71
  char * this_flag;
 
72
 
 
73
  if (cell->confirm_cb &&
 
74
      ! (cell->confirm_cb (cell->flag, cell->confirm_data)))
 
75
    return FALSE;
 
76
 
 
77
  /* Find the current flag in the list of flags */
 
78
  this_flag = strchr (cell->flag_order, cell->flag);
 
79
 
 
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;
 
83
 
 
84
  } else {
 
85
    /* It is in the list -- choose the -next- item in the list (wrapping
 
86
     * around as necessary).
 
87
     */
 
88
    this_flag++;
 
89
    if (*this_flag != '\0')
 
90
      cell->flag = *this_flag;
 
91
    else
 
92
      cell->flag = *(cell->flag_order);
 
93
  }
 
94
 
 
95
  /* And set the display */
 
96
  gnc_recn_cell_set_flag (cell, cell->flag);
 
97
 
 
98
  return FALSE;
 
99
}
 
100
 
 
101
static void
 
102
gnc_recn_cell_init (RecnCell *cell)
 
103
{
 
104
  gnc_basic_cell_init (&cell->cell);
 
105
 
 
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 = "";
 
111
 
 
112
  cell->cell.enter_cell = gnc_recn_cell_enter;
 
113
  cell->cell.set_value = gnc_recn_cell_set_value;
 
114
}
 
115
 
 
116
BasicCell *
 
117
gnc_recn_cell_new (void)
 
118
{
 
119
  RecnCell * cell;
 
120
 
 
121
  cell = g_new0 (RecnCell, 1);
 
122
 
 
123
  gnc_recn_cell_init (cell);
 
124
 
 
125
  return &cell->cell;
 
126
}
 
127
 
 
128
/* assumes we are given the untranslated form */
 
129
static void
 
130
gnc_recn_cell_set_value (BasicCell *_cell, const char *value)
 
131
{
 
132
  RecnCell *cell = (RecnCell *) _cell;
 
133
  char flag;
 
134
 
 
135
  if (!value || *value == '\0')
 
136
  {
 
137
    cell->flag = cell->default_flag;
 
138
    gnc_basic_cell_set_value_internal (_cell, "");
 
139
    return;
 
140
  }
 
141
 
 
142
  flag = cell->default_flag;
 
143
  if (strchr (cell->valid_flags, *value) != NULL)
 
144
    flag = *value;
 
145
 
 
146
  gnc_recn_cell_set_flag (cell, flag);
 
147
}
 
148
 
 
149
void
 
150
gnc_recn_cell_set_flag (RecnCell *cell, char flag)
 
151
{
 
152
  const char *string;
 
153
 
 
154
  g_return_if_fail (cell != NULL);
 
155
 
 
156
  cell->flag = flag;
 
157
  string = gnc_recn_cell_get_string (cell, flag);
 
158
 
 
159
  gnc_basic_cell_set_value_internal (&cell->cell, string);
 
160
}
 
161
 
 
162
char
 
163
gnc_recn_cell_get_flag (RecnCell *cell)
 
164
{
 
165
  g_return_val_if_fail (cell != NULL, '\0');
 
166
 
 
167
  return cell->flag;
 
168
}
 
169
 
 
170
void
 
171
gnc_recn_cell_set_string_getter (RecnCell *cell,
 
172
                                 RecnCellStringGetter get_string)
 
173
{
 
174
  g_return_if_fail (cell != NULL);
 
175
  cell->get_string = get_string;
 
176
}
 
177
 
 
178
void
 
179
gnc_recn_cell_set_confirm_cb (RecnCell *cell, RecnCellConfirm confirm_cb,
 
180
                              gpointer data)
 
181
{
 
182
  g_return_if_fail (cell != NULL);
 
183
 
 
184
  cell->confirm_cb = confirm_cb;
 
185
  cell->confirm_data = data;
 
186
}
 
187
 
 
188
void
 
189
gnc_recn_cell_set_valid_flags (RecnCell *cell, const char *flags,
 
190
                               char default_flag)
 
191
{
 
192
  g_return_if_fail (cell != NULL);
 
193
  g_return_if_fail (flags != NULL);
 
194
 
 
195
  cell->valid_flags = (char *)flags;
 
196
  cell->default_flag = default_flag;
 
197
}
 
198
 
 
199
void
 
200
gnc_recn_cell_set_flag_order (RecnCell *cell, const char *flags)
 
201
{
 
202
  g_return_if_fail (cell != NULL);
 
203
  g_return_if_fail (flags != NULL);
 
204
 
 
205
  cell->flag_order = (char *)flags;
 
206
}