checkboxcell.c

00001 /********************************************************************\
00002  * checkboxcell.c -- yes/no checkbox cell                           *
00003  *                                                                  *
00004  * This program is free software; you can redistribute it and/or    *
00005  * modify it under the terms of the GNU General Public License as   *
00006  * published by the Free Software Foundation; either version 2 of   *
00007  * the License, or (at your option) any later version.              *
00008  *                                                                  *
00009  * This program is distributed in the hope that it will be useful,  *
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00012  * GNU General Public License for more details.                     *
00013  *                                                                  *
00014  * You should have received a copy of the GNU General Public License*
00015  * along with this program; if not, contact:                        *
00016  *                                                                  *
00017  * Free Software Foundation           Voice:  +1-617-542-5942       *
00018  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
00019  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
00020  *                                                                  *
00021 \********************************************************************/
00022 
00023 /*
00024  * FILE:
00025  * checkboxcell.c
00026  * 
00027  * FUNCTION:
00028  * Implements a mouse-click cell that toggles a yes/no value.
00029  *
00030  * HISTORY:
00031  * Copyright (c) 1998 Linas Vepstas
00032  * Copyright (c) 2000 Dave Peticolas
00033  * Copyright (c) 2001 Derek Atkins
00034  */
00035 
00036 #include "config.h"
00037 
00038 #include <stdlib.h>
00039 #include <string.h>
00040 #include <time.h>
00041 
00042 #include "basiccell.h"
00043 #include "gnc-engine.h"
00044 #include "checkboxcell.h"
00045 
00046 
00047 /* assumes we are given the untranslated form */
00048 static void
00049 gnc_checkbox_cell_set_value (BasicCell *_cell, const char *value)
00050 {
00051   CheckboxCell *cell = (CheckboxCell *) _cell;
00052   gboolean flag = FALSE;
00053 
00054   if (value && *value == 'X')
00055     flag = TRUE;
00056 
00057   gnc_checkbox_cell_set_flag (cell, flag);
00058 }
00059 
00060 static gboolean
00061 gnc_checkbox_cell_enter (BasicCell *_cell,
00062                      int *cursor_position,
00063                      int *start_selection,
00064                      int *end_selection)
00065 {
00066   CheckboxCell *cell = (CheckboxCell *) _cell;
00067   gnc_checkbox_cell_set_flag (cell, !cell->flag);
00068   return FALSE;
00069 }
00070 
00071 static void
00072 gnc_checkbox_cell_init (CheckboxCell *cell)
00073 {
00074   gnc_basic_cell_init (&cell->cell);
00075 
00076   gnc_checkbox_cell_set_flag (cell, FALSE);
00077   cell->cell.enter_cell = gnc_checkbox_cell_enter;
00078   cell->cell.set_value = gnc_checkbox_cell_set_value;
00079 }
00080 
00081 BasicCell *
00082 gnc_checkbox_cell_new (void)
00083 {
00084   CheckboxCell * cell;
00085 
00086   cell = g_new0 (CheckboxCell, 1);
00087 
00088   gnc_checkbox_cell_init (cell);
00089 
00090   return &cell->cell;
00091 }
00092 
00093 void
00094 gnc_checkbox_cell_set_flag (CheckboxCell *cell, gboolean flag)
00095 {
00096   const char *string;
00097 
00098   g_return_if_fail (cell != NULL);
00099 
00100   cell->flag = flag;
00101   string = gnc_checkbox_cell_get_string (flag);
00102 
00103   gnc_basic_cell_set_value_internal (&cell->cell, string);
00104 }
00105 
00106 gboolean
00107 gnc_checkbox_cell_get_flag (CheckboxCell *cell)
00108 {
00109   g_return_val_if_fail (cell != NULL, '\0');
00110 
00111   return cell->flag;
00112 }
00113 
00114 const char *
00115 gnc_checkbox_cell_get_string (gboolean flag)
00116 {
00117   return (flag ? "X" : " ");
00118 }

Generated on Tue Oct 14 05:04:24 2008 for GnuCash by  doxygen 1.5.2