GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
checkboxcell.c
1 /********************************************************************\
2  * checkboxcell.c -- yes/no 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 [email protected] *
20  * *
21 \********************************************************************/
22 
23 /*
24  * FILE:
25  * checkboxcell.c
26  *
27  * FUNCTION:
28  * Implements a mouse-click cell that toggles a yes/no value.
29  *
30  * HISTORY:
31  * Copyright (c) 1998 Linas Vepstas
32  * Copyright (c) 2000 Dave Peticolas
33  * Copyright (c) 2001 Derek Atkins
34  */
35 
36 #include "config.h"
37 
38 #include <stdlib.h>
39 #include <string.h>
40 #include <time.h>
41 
42 #include "basiccell.h"
43 #include "gnc-engine.h"
44 #include "checkboxcell.h"
45 
46 
47 /* assumes we are given the untranslated form */
48 static void
49 gnc_checkbox_cell_set_value (BasicCell *_cell, const char *value)
50 {
51  CheckboxCell *cell = (CheckboxCell *) _cell;
52  gboolean flag = FALSE;
53 
54  if (value && *value == 'X')
55  flag = TRUE;
56 
57  gnc_checkbox_cell_set_flag (cell, flag);
58 }
59 
60 static gboolean
61 gnc_checkbox_cell_enter (BasicCell *_cell,
62  int *cursor_position,
63  int *start_selection,
64  int *end_selection)
65 {
66  CheckboxCell *cell = (CheckboxCell *) _cell;
67  gnc_checkbox_cell_set_flag (cell, !cell->flag);
68  return FALSE;
69 }
70 
71 static void
72 gnc_checkbox_cell_init (CheckboxCell *cell)
73 {
74  gnc_basic_cell_init (&cell->cell);
75 
76  gnc_checkbox_cell_set_flag (cell, FALSE);
77  cell->cell.enter_cell = gnc_checkbox_cell_enter;
78  cell->cell.set_value = gnc_checkbox_cell_set_value;
79 }
80 
81 BasicCell *
82 gnc_checkbox_cell_new (void)
83 {
84  CheckboxCell * cell;
85 
86  cell = g_new0 (CheckboxCell, 1);
87 
88  gnc_checkbox_cell_init (cell);
89 
90  return &cell->cell;
91 }
92 
93 void
94 gnc_checkbox_cell_set_flag (CheckboxCell *cell, gboolean flag)
95 {
96  const char *string;
97 
98  g_return_if_fail (cell != NULL);
99 
100  cell->flag = flag;
101  string = gnc_checkbox_cell_get_string (flag);
102 
103  gnc_basic_cell_set_value_internal (&cell->cell, string);
104 }
105 
106 gboolean
107 gnc_checkbox_cell_get_flag (CheckboxCell *cell)
108 {
109  g_return_val_if_fail (cell != NULL, '\0');
110 
111  return cell->flag;
112 }
113 
114 const char *
115 gnc_checkbox_cell_get_string (gboolean flag)
116 {
117  return (flag ? "X" : " ");
118 }
All type declarations for the whole Gnucash engine.