1 /********************************************************************\
2  * register-common.c -- Common functions for the register           *
3  * Copyright (c) 2001 Dave Peticolas                                *
4  *                                                                  *
5  * This program is free software; you can redistribute it and/or    *
6  * modify it under the terms of the GNU General Public License as   *
7  * published by the Free Software Foundation; either version 2 of   *
8  * the License, or (at your option) any later version.              *
9  *                                                                  *
10  * This program is distributed in the hope that it will be useful,  *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
13  * GNU General Public License for more details.                     *
14  *                                                                  *
15  * You should have received a copy of the GNU General Public License*
16  * along with this program; if not, contact:                        *
17  *                                                                  *
18  * Free Software Foundation           Voice:  +1-617-542-5942       *
19  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
20  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
21  *                                                                  *
22 \********************************************************************/
23 
24 #include <config.h>
25 
26 #include "doclinkcell.h"
27 #include "basiccell.h"
28 #include "cell-factory.h"
29 #include "combocell.h"
30 #include "datecell.h"
31 #include "formulacell.h"
32 #include "numcell.h"
33 #include "pricecell.h"
34 #include "recncell.h"
35 #include "checkboxcell.h"
36 #include "register-common.h"
37 #include "quickfillcell.h"
38 
39 
40 static gboolean register_inited = FALSE;
41 static CellFactory *global_factory = NULL;
42 
43 void
gnc_register_init(void)44 gnc_register_init (void)
45 {
46     if (register_inited)
47         return;
48 
49     register_inited = TRUE;
50 
51     global_factory = gnc_cell_factory_new ();
52 
53     gnc_register_add_cell_type (BASIC_CELL_TYPE_NAME, gnc_basic_cell_new);
54 
55     gnc_register_add_cell_type (NUM_CELL_TYPE_NAME, gnc_num_cell_new);
56 
57     gnc_register_add_cell_type (PRICE_CELL_TYPE_NAME, gnc_price_cell_new);
58 
59     gnc_register_add_cell_type (RECN_CELL_TYPE_NAME, gnc_recn_cell_new);
60 
61     gnc_register_add_cell_type (DOCLINK_CELL_TYPE_NAME, gnc_doclink_cell_new);
62 
63     gnc_register_add_cell_type (QUICKFILL_CELL_TYPE_NAME,
64                                 gnc_quickfill_cell_new);
65 
66     gnc_register_add_cell_type (FORMULA_CELL_TYPE_NAME,
67                                 gnc_formula_cell_new);
68 
69     gnc_register_add_cell_type (CHECKBOX_CELL_TYPE_NAME, gnc_checkbox_cell_new);
70 }
71 
72 void
gnc_register_shutdown(void)73 gnc_register_shutdown (void)
74 {
75     if (!register_inited)
76         return;
77 
78     gnc_cell_factory_destroy (global_factory);
79     global_factory = NULL;
80 }
81 
82 void
gnc_register_add_cell_type(const char * cell_type_name,CellCreateFunc cell_creator)83 gnc_register_add_cell_type (const char *cell_type_name,
84                             CellCreateFunc cell_creator)
85 {
86     gnc_register_init ();
87 
88     gnc_cell_factory_add_cell_type (global_factory,
89                                     cell_type_name, cell_creator);
90 }
91 
92 BasicCell *
gnc_register_make_cell(const char * cell_type_name)93 gnc_register_make_cell (const char *cell_type_name)
94 {
95     gnc_register_init ();
96 
97     return gnc_cell_factory_make_cell (global_factory, cell_type_name);
98 }
99 
100 gboolean
virt_cell_loc_equal(VirtualCellLocation vcl1,VirtualCellLocation vcl2)101 virt_cell_loc_equal (VirtualCellLocation vcl1, VirtualCellLocation vcl2)
102 {
103     return ((vcl1.virt_row == vcl2.virt_row) &&
104             (vcl1.virt_col == vcl2.virt_col));
105 }
106 
107 gboolean
virt_loc_equal(VirtualLocation vl1,VirtualLocation vl2)108 virt_loc_equal (VirtualLocation vl1, VirtualLocation vl2)
109 {
110     return (virt_cell_loc_equal (vl1.vcell_loc, vl2.vcell_loc) &&
111             (vl1.phys_row_offset == vl2.phys_row_offset) &&
112             (vl1.phys_col_offset == vl2.phys_col_offset));
113 }
114