GnuCash  5.6-150-g038405b370+
split-register-layout.c
1 /********************************************************************\
2  * split-register-layout.c -- split register layout object *
3  * Copyright (C) 1998 Linas Vepstas <linas@linas.org> *
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 <glib.h>
27 #include <glib/gi18n.h>
28 
29 #include "gnc-engine.h"
30 #include "split-register-layout.h"
31 
32 
33 /* This static indicates the debugging module that this .o belongs to. */
34 static QofLogModule log_module = GNC_MOD_REGISTER;
35 
36 
37 static void
38 gnc_register_add_cell (TableLayout* layout,
39  const char* cell_name,
40  const char* cell_type_name,
41  const char* sample_text,
42  CellAlignment alignment,
43  gboolean expandable,
44  gboolean span)
45 {
46  BasicCell* cell;
47 
48  g_return_if_fail (layout != NULL);
49  g_return_if_fail (cell_type_name != NULL);
50 
51  cell = gnc_register_make_cell (cell_type_name);
52 
53  gnc_basic_cell_set_name (cell, cell_name);
54  gnc_basic_cell_set_type_name (cell, cell_type_name);
55  gnc_basic_cell_set_sample_text (cell, sample_text);
56  gnc_basic_cell_set_alignment (cell, alignment);
57  gnc_basic_cell_set_expandable (cell, expandable);
58  gnc_basic_cell_set_span (cell, span);
59 
60  gnc_table_layout_add_cell (layout, cell);
61 }
62 
63 static void
64 copy_cursor_row (TableLayout* layout, CellBlock* to, CellBlock* from, int row)
65 {
66  int col;
67 
68  for (col = 0; col < from->num_cols; col++)
69  {
70  BasicCell* cell;
71 
72  cell = gnc_cellblock_get_cell (from, row, col);
73  if (!cell || !cell->cell_name)
74  continue;
75 
76  gnc_table_layout_set_cell (layout, to, cell->cell_name, row, col);
77  }
78 }
79 
80 static void
81 gnc_split_register_set_cells (SplitRegister* reg, TableLayout* layout)
82 {
83  CellBlock* curs;
84  CellBlock* curs_last;
85 
87  {
88  case REG_TYPE_GROUP_CURRENCY:
89  {
90  curs = gnc_table_layout_get_cursor (layout,
91  CURSOR_SINGLE_LEDGER);
92 
93  gnc_table_layout_set_cell (layout, curs, DATE_CELL, 0, 0);
94  gnc_table_layout_set_cell (layout, curs, NUM_CELL, 0, 1);
95  gnc_table_layout_set_cell (layout, curs, DESC_CELL, 0, 2);
96  gnc_table_layout_set_cell (layout, curs, MXFRM_CELL, 0, 3);
97  gnc_table_layout_set_cell (layout, curs, RECN_CELL, 0, 4);
98  if (reg->is_template)
99  {
100  gnc_table_layout_set_cell (layout, curs, FDEBT_CELL, 0, 5);
101  gnc_table_layout_set_cell (layout, curs, FCRED_CELL, 0, 6);
102  }
103  else
104  {
105  gnc_table_layout_set_cell (layout, curs, DEBT_CELL, 0, 5);
106  gnc_table_layout_set_cell (layout, curs, CRED_CELL, 0, 6);
107  }
108  gnc_table_layout_set_cell (layout, curs, BALN_CELL, 0, 7);
109  gnc_table_layout_set_cell (layout, curs, RATE_CELL, 0, 8);
110 
111  curs_last = curs;
112  curs = gnc_table_layout_get_cursor (layout,
113  CURSOR_DOUBLE_LEDGER);
114 
115  copy_cursor_row (layout, curs, curs_last, 0);
116 
117  gnc_table_layout_set_cell (layout, curs, ACTN_CELL, 1, 1);
118  gnc_table_layout_set_cell (layout, curs, NOTES_CELL, 1, 2);
119  gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
120  gnc_table_layout_set_cell (layout, curs, DOCLINK_CELL, 1, 4);
121 
122  curs = gnc_table_layout_get_cursor (layout,
123  CURSOR_DOUBLE_LEDGER_NUM_ACTN);
124 
125  copy_cursor_row (layout, curs, curs_last, 0);
126 
127  gnc_table_layout_set_cell (layout, curs, TNUM_CELL, 1, 1);
128  gnc_table_layout_set_cell (layout, curs, NOTES_CELL, 1, 2);
129  gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
130  gnc_table_layout_set_cell (layout, curs, DOCLINK_CELL, 1, 4);
131 
132  curs = gnc_table_layout_get_cursor (layout,
133  CURSOR_SINGLE_JOURNAL);
134 
135  gnc_table_layout_set_cell (layout, curs, DATE_CELL, 0, 0);
136  gnc_table_layout_set_cell (layout, curs, NUM_CELL, 0, 1);
137  gnc_table_layout_set_cell (layout, curs, DESC_CELL, 0, 2);
138  gnc_table_layout_set_cell (layout, curs, TDEBT_CELL, 0, 5);
139  gnc_table_layout_set_cell (layout, curs, TCRED_CELL, 0, 6);
140  gnc_table_layout_set_cell (layout, curs, TBALN_CELL, 0, 7);
141  gnc_table_layout_set_cell (layout, curs, RATE_CELL, 0, 8);
142 
143  curs_last = curs;
144  curs = gnc_table_layout_get_cursor (layout,
145  CURSOR_DOUBLE_JOURNAL);
146 
147  copy_cursor_row (layout, curs, curs_last, 0);
148 
149  gnc_table_layout_set_cell (layout, curs, NOTES_CELL, 1, 2);
150  gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
151  gnc_table_layout_set_cell (layout, curs, DOCLINK_CELL, 1, 4);
152 
153  curs = gnc_table_layout_get_cursor (layout,
154  CURSOR_DOUBLE_JOURNAL_NUM_ACTN);
155 
156  copy_cursor_row (layout, curs, curs_last, 0);
157 
158  gnc_table_layout_set_cell (layout, curs, TNUM_CELL, 1, 1);
159  gnc_table_layout_set_cell (layout, curs, NOTES_CELL, 1, 2);
160  gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
161  gnc_table_layout_set_cell (layout, curs, DOCLINK_CELL, 1, 4);
162 
163  curs = gnc_table_layout_get_cursor (layout,
164  CURSOR_SPLIT);
165 
166  gnc_table_layout_set_cell (layout, curs, ACTN_CELL, 0, 1);
167  gnc_table_layout_set_cell (layout, curs, MEMO_CELL, 0, 2);
168  gnc_table_layout_set_cell (layout, curs, XFRM_CELL, 0, 3);
169  gnc_table_layout_set_cell (layout, curs, RECN_CELL, 0, 4);
170  if (reg->is_template)
171  {
172  gnc_table_layout_set_cell (layout, curs, FDEBT_CELL, 0, 5);
173  gnc_table_layout_set_cell (layout, curs, FCRED_CELL, 0, 6);
174  }
175  else
176  {
177  gnc_table_layout_set_cell (layout, curs, DEBT_CELL, 0, 5);
178  gnc_table_layout_set_cell (layout, curs, CRED_CELL, 0, 6);
179  }
180  gnc_table_layout_set_cell (layout, curs, RATE_CELL, 0, 8);
181 
182  break;
183  }
184  /* --------------------------------------------------------- */
185 
186  case REG_TYPE_GROUP_APAR:
187  {
188  curs = gnc_table_layout_get_cursor (layout,
189  CURSOR_SINGLE_LEDGER);
190 
191  gnc_table_layout_set_cell (layout, curs, DATE_CELL, 0, 0);
192  gnc_table_layout_set_cell (layout, curs, TYPE_CELL, 0, 1);
193  gnc_table_layout_set_cell (layout, curs, DDUE_CELL, 0, 2);
194  gnc_table_layout_set_cell (layout, curs, NUM_CELL, 0, 3);
195  gnc_table_layout_set_cell (layout, curs, DESC_CELL, 0, 4);
196  gnc_table_layout_set_cell (layout, curs, MXFRM_CELL, 0, 5);
197  gnc_table_layout_set_cell (layout, curs, DEBT_CELL, 0, 6);
198  gnc_table_layout_set_cell (layout, curs, CRED_CELL, 0, 7);
199  gnc_table_layout_set_cell (layout, curs, BALN_CELL, 0, 8);
200  gnc_table_layout_set_cell (layout, curs, RATE_CELL, 0, 9);
201 
202  curs_last = curs;
203  curs = gnc_table_layout_get_cursor (layout,
204  CURSOR_DOUBLE_LEDGER);
205 
206  copy_cursor_row (layout, curs, curs_last, 0);
207 
208  gnc_table_layout_set_cell (layout, curs, DOCLINK_CELL, 1, 1);
209  gnc_table_layout_set_cell (layout, curs, ACTN_CELL, 1, 3);
210  gnc_table_layout_set_cell (layout, curs, MEMO_CELL, 1, 4);
211 
212  curs = gnc_table_layout_get_cursor (layout,
213  CURSOR_DOUBLE_LEDGER_NUM_ACTN);
214 
215  copy_cursor_row (layout, curs, curs_last, 0);
216 
217  gnc_table_layout_set_cell (layout, curs, DOCLINK_CELL, 1, 1);
218  gnc_table_layout_set_cell (layout, curs, TNUM_CELL, 1, 3);
219  gnc_table_layout_set_cell (layout, curs, MEMO_CELL, 1, 4);
220 
221  curs = gnc_table_layout_get_cursor (layout,
222  CURSOR_SINGLE_JOURNAL);
223 
224  gnc_table_layout_set_cell (layout, curs, DATE_CELL, 0, 0);
225  gnc_table_layout_set_cell (layout, curs, TYPE_CELL, 0, 1);
226  gnc_table_layout_set_cell (layout, curs, DDUE_CELL, 0, 2);
227  gnc_table_layout_set_cell (layout, curs, NUM_CELL, 0, 3);
228  gnc_table_layout_set_cell (layout, curs, DESC_CELL, 0, 4);
229 
230  gnc_table_layout_set_cell (layout, curs, TDEBT_CELL, 0, 6);
231  gnc_table_layout_set_cell (layout, curs, TCRED_CELL, 0, 7);
232  gnc_table_layout_set_cell (layout, curs, TBALN_CELL, 0, 8);
233  gnc_table_layout_set_cell (layout, curs, RATE_CELL, 0, 9);
234 
235  curs_last = curs;
236  curs = gnc_table_layout_get_cursor (layout,
237  CURSOR_DOUBLE_JOURNAL);
238 
239  copy_cursor_row (layout, curs, curs_last, 0);
240 
241  gnc_table_layout_set_cell (layout, curs, MEMO_CELL, 1, 4);
242 
243  curs = gnc_table_layout_get_cursor (layout,
244  CURSOR_DOUBLE_JOURNAL_NUM_ACTN);
245 
246  copy_cursor_row (layout, curs, curs_last, 0);
247 
248  gnc_table_layout_set_cell (layout, curs, DOCLINK_CELL, 1, 1);
249  gnc_table_layout_set_cell (layout, curs, TNUM_CELL, 1, 3);
250  gnc_table_layout_set_cell (layout, curs, MEMO_CELL, 1, 4);
251 
252  curs = gnc_table_layout_get_cursor (layout,
253  CURSOR_SPLIT);
254 
255  gnc_table_layout_set_cell (layout, curs, ACTN_CELL, 0, 3);
256  gnc_table_layout_set_cell (layout, curs, MEMO_CELL, 0, 4);
257  gnc_table_layout_set_cell (layout, curs, XFRM_CELL, 0, 5);
258  gnc_table_layout_set_cell (layout, curs, DEBT_CELL, 0, 6);
259  gnc_table_layout_set_cell (layout, curs, CRED_CELL, 0, 7);
260 
261  break;
262  }
263 
264  /* --------------------------------------------------------- */
265  case REG_TYPE_GROUP_JOURNAL:
266  {
267  curs = gnc_table_layout_get_cursor (layout,
268  CURSOR_SINGLE_LEDGER);
269 
270  gnc_table_layout_set_cell (layout, curs, DATE_CELL, 0, 0);
271  gnc_table_layout_set_cell (layout, curs, TNUM_CELL, 0, 1);
272  gnc_table_layout_set_cell (layout, curs, DESC_CELL, 0, 2);
273  gnc_table_layout_set_cell (layout, curs, MXFRM_CELL, 0, 3);
274  gnc_table_layout_set_cell (layout, curs, RECN_CELL, 0, 4);
275  if (reg->is_template)
276  {
277  gnc_table_layout_set_cell (layout, curs, FDEBT_CELL, 0, 5);
278  gnc_table_layout_set_cell (layout, curs, FCRED_CELL, 0, 6);
279  gnc_table_layout_set_cell (layout, curs, RATE_CELL, 0, 7);
280  }
281  else
282  {
283  gnc_table_layout_set_cell (layout, curs, DEBT_CELL, 0, 5);
284  gnc_table_layout_set_cell (layout, curs, CRED_CELL, 0, 6);
285  if (!reg->mismatched_commodities)
286  {
287  gnc_table_layout_set_cell (layout, curs, RBALN_CELL, 0, 7);
288  gnc_table_layout_set_cell (layout, curs, RATE_CELL, 0, 8);
289  }
290  else
291  {
292  // Don't display the balance if there are mismatched commodities
293  gnc_table_layout_set_cell (layout, curs, RATE_CELL, 0, 7);
294  }
295  }
296 
297  curs_last = curs;
298  curs = gnc_table_layout_get_cursor (layout,
299  CURSOR_DOUBLE_LEDGER);
300 
301  copy_cursor_row (layout, curs, curs_last, 0);
302 
303  gnc_table_layout_set_cell (layout, curs, ACTN_CELL, 1, 1);
304  gnc_table_layout_set_cell (layout, curs, NOTES_CELL, 1, 2);
305  gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
306  gnc_table_layout_set_cell (layout, curs, DOCLINK_CELL, 1, 4);
307 
308  curs = gnc_table_layout_get_cursor (layout,
309  CURSOR_DOUBLE_LEDGER_NUM_ACTN);
310 
311  copy_cursor_row (layout, curs, curs_last, 0);
312 
313  gnc_table_layout_set_cell (layout, curs, ACTN_CELL, 1, 1);
314  gnc_table_layout_set_cell (layout, curs, NOTES_CELL, 1, 2);
315  gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
316  gnc_table_layout_set_cell (layout, curs, DOCLINK_CELL, 1, 4);
317 
318  curs = gnc_table_layout_get_cursor (layout,
319  CURSOR_SINGLE_JOURNAL);
320 
321  gnc_table_layout_set_cell (layout, curs, DATE_CELL, 0, 0);
322  gnc_table_layout_set_cell (layout, curs, TNUM_CELL, 0, 1);
323  gnc_table_layout_set_cell (layout, curs, DESC_CELL, 0, 2);
324  gnc_table_layout_set_cell (layout, curs, TDEBT_CELL, 0, 5);
325  gnc_table_layout_set_cell (layout, curs, TCRED_CELL, 0, 6);
326  if (reg->is_template)
327  gnc_table_layout_set_cell (layout, curs, RATE_CELL, 0, 7);
328  else
329  {
330  if (!reg->mismatched_commodities)
331  {
332  gnc_table_layout_set_cell (layout, curs, RBALN_CELL, 0, 7);
333  gnc_table_layout_set_cell (layout, curs, RATE_CELL, 0, 8);
334  }
335  else
336  {
337  // Don't display the balance if there are mismatched commodities
338  gnc_table_layout_set_cell (layout, curs, RATE_CELL, 0, 7);
339  }
340  }
341 
342  curs_last = curs;
343  curs = gnc_table_layout_get_cursor (layout,
344  CURSOR_DOUBLE_JOURNAL);
345 
346  copy_cursor_row (layout, curs, curs_last, 0);
347 
348  gnc_table_layout_set_cell (layout, curs, NOTES_CELL, 1, 2);
349  gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
350  gnc_table_layout_set_cell (layout, curs, DOCLINK_CELL, 1, 4);
351 
352  curs = gnc_table_layout_get_cursor (layout,
353  CURSOR_DOUBLE_JOURNAL_NUM_ACTN);
354 
355  copy_cursor_row (layout, curs, curs_last, 0);
356 
357  gnc_table_layout_set_cell (layout, curs, NOTES_CELL, 1, 2);
358  gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
359  gnc_table_layout_set_cell (layout, curs, DOCLINK_CELL, 1, 4);
360 
361  curs = gnc_table_layout_get_cursor (layout,
362  CURSOR_SPLIT);
363 
364  gnc_table_layout_set_cell (layout, curs, ACTN_CELL, 0, 1);
365  gnc_table_layout_set_cell (layout, curs, MEMO_CELL, 0, 2);
366  gnc_table_layout_set_cell (layout, curs, XFRM_CELL, 0, 3);
367  gnc_table_layout_set_cell (layout, curs, RECN_CELL, 0, 4);
368  if (reg->is_template)
369  {
370  gnc_table_layout_set_cell (layout, curs, FDEBT_CELL, 0, 5);
371  gnc_table_layout_set_cell (layout, curs, FCRED_CELL, 0, 6);
372  gnc_table_layout_set_cell (layout, curs, RATE_CELL, 0, 7);
373  }
374  else
375  {
376  gnc_table_layout_set_cell (layout, curs, DEBT_CELL, 0, 5);
377  gnc_table_layout_set_cell (layout, curs, CRED_CELL, 0, 6);
378  gnc_table_layout_set_cell (layout, curs, RATE_CELL, 0, 8);
379  }
380 
381  break;
382  }
383 
384  /* --------------------------------------------------------- */
385  case REG_TYPE_GROUP_STOCK:
386  {
387  curs = gnc_table_layout_get_cursor (layout,
388  CURSOR_SINGLE_LEDGER);
389 
390  gnc_table_layout_set_cell (layout, curs, DATE_CELL, 0, 0);
391  gnc_table_layout_set_cell (layout, curs, NUM_CELL, 0, 1);
392  gnc_table_layout_set_cell (layout, curs, DESC_CELL, 0, 2);
393  gnc_table_layout_set_cell (layout, curs, MXFRM_CELL, 0, 3);
394  gnc_table_layout_set_cell (layout, curs, RECN_CELL, 0, 4);
395  gnc_table_layout_set_cell (layout, curs, SHRS_CELL, 0, 5);
396  gnc_table_layout_set_cell (layout, curs, PRIC_CELL, 0, 6);
397  gnc_table_layout_set_cell (layout, curs, DEBT_CELL, 0, 7);
398  gnc_table_layout_set_cell (layout, curs, CRED_CELL, 0, 8);
399  gnc_table_layout_set_cell (layout, curs, BALN_CELL, 0, 9);
400 
401  curs_last = curs;
402  curs = gnc_table_layout_get_cursor (layout,
403  CURSOR_DOUBLE_LEDGER);
404 
405  copy_cursor_row (layout, curs, curs_last, 0);
406 
407  gnc_table_layout_set_cell (layout, curs, ACTN_CELL, 1, 1);
408  gnc_table_layout_set_cell (layout, curs, NOTES_CELL, 1, 2);
409  gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
410  gnc_table_layout_set_cell (layout, curs, DOCLINK_CELL, 1, 4);
411 
412  curs = gnc_table_layout_get_cursor (layout,
413  CURSOR_DOUBLE_LEDGER_NUM_ACTN);
414 
415  copy_cursor_row (layout, curs, curs_last, 0);
416 
417  gnc_table_layout_set_cell (layout, curs, TNUM_CELL, 1, 1);
418  gnc_table_layout_set_cell (layout, curs, NOTES_CELL, 1, 2);
419  gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
420  gnc_table_layout_set_cell (layout, curs, DOCLINK_CELL, 1, 4);
421 
422  curs = gnc_table_layout_get_cursor (layout,
423  CURSOR_SINGLE_JOURNAL);
424 
425  gnc_table_layout_set_cell (layout, curs, DATE_CELL, 0, 0);
426  gnc_table_layout_set_cell (layout, curs, NUM_CELL, 0, 1);
427  gnc_table_layout_set_cell (layout, curs, DESC_CELL, 0, 2);
428  gnc_table_layout_set_cell (layout, curs, TSHRS_CELL, 0, 5);
429  gnc_table_layout_set_cell (layout, curs, TDEBT_CELL, 0, 7);
430  gnc_table_layout_set_cell (layout, curs, TCRED_CELL, 0, 8);
431  gnc_table_layout_set_cell (layout, curs, TBALN_CELL, 0, 9);
432 
433  curs_last = curs;
434  curs = gnc_table_layout_get_cursor (layout,
435  CURSOR_DOUBLE_JOURNAL);
436 
437  copy_cursor_row (layout, curs, curs_last, 0);
438 
439  gnc_table_layout_set_cell (layout, curs, NOTES_CELL, 1, 2);
440  gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
441  gnc_table_layout_set_cell (layout, curs, DOCLINK_CELL, 1, 4);
442 
443  curs = gnc_table_layout_get_cursor (layout,
444  CURSOR_DOUBLE_JOURNAL_NUM_ACTN);
445 
446  copy_cursor_row (layout, curs, curs_last, 0);
447 
448  gnc_table_layout_set_cell (layout, curs, TNUM_CELL, 1, 1);
449  gnc_table_layout_set_cell (layout, curs, NOTES_CELL, 1, 2);
450  gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
451  gnc_table_layout_set_cell (layout, curs, DOCLINK_CELL, 1, 4);
452 
453  curs = gnc_table_layout_get_cursor (layout,
454  CURSOR_SPLIT);
455 
456  gnc_table_layout_set_cell (layout, curs, ACTN_CELL, 0, 1);
457  gnc_table_layout_set_cell (layout, curs, MEMO_CELL, 0, 2);
458  gnc_table_layout_set_cell (layout, curs, XFRM_CELL, 0, 3);
459  gnc_table_layout_set_cell (layout, curs, RECN_CELL, 0, 4);
460  gnc_table_layout_set_cell (layout, curs, SHRS_CELL, 0, 5);
461  gnc_table_layout_set_cell (layout, curs, PRIC_CELL, 0, 6);
462  gnc_table_layout_set_cell (layout, curs, DEBT_CELL, 0, 7);
463  gnc_table_layout_set_cell (layout, curs, CRED_CELL, 0, 8);
464 
465  break;
466  }
467 
468  /* --------------------------------------------------------- */
469  case REG_TYPE_GROUP_PORTFOLIO:
470  {
471  curs = gnc_table_layout_get_cursor (layout,
472  CURSOR_SINGLE_LEDGER);
473 
474  gnc_table_layout_set_cell (layout, curs, DATE_CELL, 0, 0);
475  gnc_table_layout_set_cell (layout, curs, NUM_CELL, 0, 1);
476  gnc_table_layout_set_cell (layout, curs, DESC_CELL, 0, 2);
477  gnc_table_layout_set_cell (layout, curs, MXFRM_CELL, 0, 3);
478  gnc_table_layout_set_cell (layout, curs, RECN_CELL, 0, 4);
479  gnc_table_layout_set_cell (layout, curs, SHRS_CELL, 0, 5);
480  gnc_table_layout_set_cell (layout, curs, PRIC_CELL, 0, 6);
481  gnc_table_layout_set_cell (layout, curs, DEBT_CELL, 0, 7);
482  gnc_table_layout_set_cell (layout, curs, CRED_CELL, 0, 8);
483 
484  curs_last = curs;
485  curs = gnc_table_layout_get_cursor (layout,
486  CURSOR_DOUBLE_LEDGER);
487 
488  copy_cursor_row (layout, curs, curs_last, 0);
489 
490  gnc_table_layout_set_cell (layout, curs, ACTN_CELL, 1, 1);
491  gnc_table_layout_set_cell (layout, curs, NOTES_CELL, 1, 2);
492  gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
493  gnc_table_layout_set_cell (layout, curs, DOCLINK_CELL, 1, 4);
494 
495  curs = gnc_table_layout_get_cursor (layout,
496  CURSOR_DOUBLE_LEDGER_NUM_ACTN);
497 
498  copy_cursor_row (layout, curs, curs_last, 0);
499 
500  gnc_table_layout_set_cell (layout, curs, TNUM_CELL, 1, 1);
501  gnc_table_layout_set_cell (layout, curs, NOTES_CELL, 1, 2);
502  gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
503  gnc_table_layout_set_cell (layout, curs, DOCLINK_CELL, 1, 4);
504 
505  curs = gnc_table_layout_get_cursor (layout,
506  CURSOR_SINGLE_JOURNAL);
507 
508  gnc_table_layout_set_cell (layout, curs, DATE_CELL, 0, 0);
509  gnc_table_layout_set_cell (layout, curs, NUM_CELL, 0, 1);
510  gnc_table_layout_set_cell (layout, curs, DESC_CELL, 0, 2);
511  gnc_table_layout_set_cell (layout, curs, TSHRS_CELL, 0, 5);
512  gnc_table_layout_set_cell (layout, curs, TDEBT_CELL, 0, 7);
513  gnc_table_layout_set_cell (layout, curs, TCRED_CELL, 0, 8);
514 
515  curs_last = curs;
516  curs = gnc_table_layout_get_cursor (layout,
517  CURSOR_DOUBLE_JOURNAL);
518 
519  copy_cursor_row (layout, curs, curs_last, 0);
520 
521  gnc_table_layout_set_cell (layout, curs, NOTES_CELL, 1, 2);
522  gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
523  gnc_table_layout_set_cell (layout, curs, DOCLINK_CELL, 1, 4);
524 
525  curs = gnc_table_layout_get_cursor (layout,
526  CURSOR_DOUBLE_JOURNAL_NUM_ACTN);
527 
528  copy_cursor_row (layout, curs, curs_last, 0);
529 
530  gnc_table_layout_set_cell (layout, curs, TNUM_CELL, 1, 1);
531  gnc_table_layout_set_cell (layout, curs, NOTES_CELL, 1, 2);
532  gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
533  gnc_table_layout_set_cell (layout, curs, DOCLINK_CELL, 1, 4);
534 
535  curs = gnc_table_layout_get_cursor (layout,
536  CURSOR_SPLIT);
537 
538  gnc_table_layout_set_cell (layout, curs, ACTN_CELL, 0, 1);
539  gnc_table_layout_set_cell (layout, curs, MEMO_CELL, 0, 2);
540  gnc_table_layout_set_cell (layout, curs, XFRM_CELL, 0, 3);
541  gnc_table_layout_set_cell (layout, curs, RECN_CELL, 0, 4);
542  gnc_table_layout_set_cell (layout, curs, SHRS_CELL, 0, 5);
543  gnc_table_layout_set_cell (layout, curs, PRIC_CELL, 0, 6);
544  gnc_table_layout_set_cell (layout, curs, DEBT_CELL, 0, 7);
545  gnc_table_layout_set_cell (layout, curs, CRED_CELL, 0, 8);
546 
547  break;
548  }
549 
550  /* --------------------------------------------------------- */
551  default:
552  PERR ("unknown register group type for %d \n", reg->type);
553  break;
554  }
555 }
556 
557 static void
558 gnc_split_register_layout_add_cursors (SplitRegister* reg,
559  TableLayout* layout)
560 {
561  CellBlock* cursor;
562  int num_cols;
563 
564  switch (reg->type)
565  {
566  case BANK_REGISTER:
567  case CASH_REGISTER:
568  case ASSET_REGISTER:
569  case CREDIT_REGISTER:
570  case LIABILITY_REGISTER:
571  case INCOME_REGISTER:
572  case EXPENSE_REGISTER:
573  case EQUITY_REGISTER:
574  case TRADING_REGISTER:
575  num_cols = 9;
576  break;
577 
578  case PAYABLE_REGISTER:
579  case RECEIVABLE_REGISTER:
580  num_cols = 10;
581  break;
582 
583  case INCOME_LEDGER:
584  case GENERAL_JOURNAL:
585  case SEARCH_LEDGER:
586  if (reg->is_template || reg->mismatched_commodities)
587  num_cols = 8;
588  else
589  num_cols = 9;
590  break;
591 
592  case STOCK_REGISTER:
593  case CURRENCY_REGISTER:
594  num_cols = 10;
595  break;
596 
597  case PORTFOLIO_LEDGER:
598  num_cols = 9;
599  break;
600 
601  default:
602  PERR ("Bad register type");
603  g_assert (FALSE);
604  return;
605  }
606 
607  cursor = gnc_cellblock_new (1, num_cols, CURSOR_HEADER);
608  gnc_table_layout_add_cursor (layout, cursor);
609 
610  /* cursors used in ledger mode */
611  cursor = gnc_cellblock_new (1, num_cols, CURSOR_SINGLE_LEDGER);
612  gnc_table_layout_add_cursor (layout, cursor);
613 
614  gnc_table_layout_set_primary_cursor (layout, cursor);
615 
616  cursor = gnc_cellblock_new (2, num_cols, CURSOR_DOUBLE_LEDGER);
617  gnc_table_layout_add_cursor (layout, cursor);
618 
619  cursor = gnc_cellblock_new (2, num_cols, CURSOR_DOUBLE_LEDGER_NUM_ACTN);
620  gnc_table_layout_add_cursor (layout, cursor);
621 
622  /* cursors used for journal mode */
623  cursor = gnc_cellblock_new (1, num_cols, CURSOR_SINGLE_JOURNAL);
624  gnc_table_layout_add_cursor (layout, cursor);
625 
626  cursor = gnc_cellblock_new (2, num_cols, CURSOR_DOUBLE_JOURNAL);
627  gnc_table_layout_add_cursor (layout, cursor);
628 
629  cursor = gnc_cellblock_new (2, num_cols, CURSOR_DOUBLE_JOURNAL_NUM_ACTN);
630  gnc_table_layout_add_cursor (layout, cursor);
631 
632  cursor = gnc_cellblock_new (1, num_cols, CURSOR_SPLIT);
633  gnc_table_layout_add_cursor (layout, cursor);
634 }
635 
636 static void
637 gnc_split_register_layout_add_cells (SplitRegister* reg,
638  TableLayout* layout)
639 {
640  gnc_register_add_cell (layout,
641  DATE_CELL,
642  DATE_CELL_TYPE_NAME,
643  /* Translators: The 'sample:' items are
644  strings which are not displayed, but only
645  used to estimate widths. */
646  C_ ("sample", "22/02/2000"),
647  CELL_ALIGN_RIGHT,
648  FALSE,
649  FALSE);
650 
651  gnc_register_add_cell (layout,
652  DDUE_CELL,
653  DATE_CELL_TYPE_NAME,
654  C_ ("sample", "22/02/2000"),
655  CELL_ALIGN_RIGHT,
656  FALSE,
657  FALSE);
658 
659  gnc_register_add_cell (layout,
660  NUM_CELL,
661  NUM_CELL_TYPE_NAME,
662  /* Translators: The 'sample' items are
663  strings which are not displayed, but only
664  used to estimate widths. */
665  C_ ("sample", "99999"),
666  CELL_ALIGN_LEFT,
667  FALSE,
668  FALSE);
669 
670  gnc_register_add_cell (layout,
671  TNUM_CELL,
672  BASIC_CELL_TYPE_NAME,
673  C_ ("sample", "99999"),
674  CELL_ALIGN_LEFT,
675  FALSE,
676  FALSE);
677 
678  gnc_register_add_cell (layout,
679  DESC_CELL,
680  COMPLETION_CELL_TYPE_NAME,
681  C_ ("sample", "Description of a transaction"),
682  CELL_ALIGN_LEFT,
683  TRUE,
684  FALSE);
685 
686  gnc_register_add_cell (layout,
687  RATE_CELL,
688  PRICE_CELL_TYPE_NAME,
689  NULL,
690  CELL_ALIGN_RIGHT,
691  FALSE,
692  FALSE);
693 
694  gnc_register_add_cell (layout,
695  RECN_CELL,
696  RECN_CELL_TYPE_NAME,
697  C_ ("Column header for 'Reconciled'", "R"),
698  CELL_ALIGN_CENTER,
699  FALSE,
700  FALSE);
701 
702  gnc_register_add_cell (layout,
703  DOCLINK_CELL,
704  DOCLINK_CELL_TYPE_NAME,
705  C_ ("Column header for 'Document Link'", "L"),
706  CELL_ALIGN_CENTER,
707  FALSE,
708  FALSE);
709 
710  gnc_register_add_cell (layout,
711  BALN_CELL,
712  PRICE_CELL_TYPE_NAME,
713  C_ ("sample", "999,999.000"),
714  CELL_ALIGN_RIGHT,
715  FALSE,
716  FALSE);
717 
718  gnc_register_add_cell (layout,
719  XFRM_CELL,
720  COMBO_CELL_TYPE_NAME,
721  _ ("Transfer"),
722  CELL_ALIGN_RIGHT,
723  FALSE,
724  FALSE);
725 
726  gnc_register_add_cell (layout,
727  MXFRM_CELL,
728  COMBO_CELL_TYPE_NAME,
729  C_ ("sample", "Expenses:Automobile:Gasoline"),
730  CELL_ALIGN_RIGHT,
731  FALSE,
732  FALSE);
733 
734  gnc_register_add_cell (layout,
735  ACTN_CELL,
736  COMBO_CELL_TYPE_NAME,
737  C_ ("sample", "Expenses:Automobile:Gasoline"),
738  CELL_ALIGN_RIGHT,
739  FALSE,
740  FALSE);
741 
742  gnc_register_add_cell (layout,
743  MEMO_CELL,
744  QUICKFILL_CELL_TYPE_NAME,
745  C_ ("sample", "Memo field sample text string"),
746  CELL_ALIGN_LEFT,
747  TRUE,
748  FALSE);
749 
750  gnc_register_add_cell (layout,
751  DEBT_CELL,
752  PRICE_CELL_TYPE_NAME,
753  C_ ("sample", "999,999.000"),
754  CELL_ALIGN_RIGHT,
755  FALSE,
756  FALSE);
757 
758  gnc_register_add_cell (layout,
759  CRED_CELL,
760  PRICE_CELL_TYPE_NAME,
761  C_ ("sample", "999,999.000"),
762  CELL_ALIGN_RIGHT,
763  FALSE,
764  FALSE);
765 
766  gnc_register_add_cell (layout,
767  SHRS_CELL,
768  PRICE_CELL_TYPE_NAME,
769  C_ ("sample", "999,999.000"),
770  CELL_ALIGN_RIGHT,
771  FALSE,
772  FALSE);
773 
774  /* Price cell must come after shares cell, as its callback performs
775  * a computation on the value set by the shares cell callback. */
776  gnc_register_add_cell (layout,
777  PRIC_CELL,
778  PRICE_CELL_TYPE_NAME,
779  C_ ("sample", "999,999.000"),
780  CELL_ALIGN_RIGHT,
781  FALSE,
782  FALSE);
783 
784  gnc_register_add_cell (layout,
785  TDEBT_CELL,
786  PRICE_CELL_TYPE_NAME,
787  C_ ("sample", "999,999.000"),
788  CELL_ALIGN_RIGHT,
789  FALSE,
790  FALSE);
791 
792  gnc_register_add_cell (layout,
793  TCRED_CELL,
794  PRICE_CELL_TYPE_NAME,
795  C_ ("sample", "999,999.000"),
796  CELL_ALIGN_RIGHT,
797  FALSE,
798  FALSE);
799 
800  gnc_register_add_cell (layout,
801  TSHRS_CELL,
802  PRICE_CELL_TYPE_NAME,
803  C_ ("sample", "999,999.000"),
804  CELL_ALIGN_RIGHT,
805  FALSE,
806  FALSE);
807 
808  gnc_register_add_cell (layout,
809  TBALN_CELL,
810  PRICE_CELL_TYPE_NAME,
811  C_ ("sample", "999,999.000"),
812  CELL_ALIGN_RIGHT,
813  FALSE,
814  FALSE);
815 
816  gnc_register_add_cell (layout,
817  TYPE_CELL,
818  RECN_CELL_TYPE_NAME,
819  C_ ("Column header for 'Type'", "T"),
820  CELL_ALIGN_CENTER,
821  FALSE,
822  FALSE);
823 
824  gnc_register_add_cell (layout,
825  NOTES_CELL,
826  QUICKFILL_CELL_TYPE_NAME,
827  C_ ("sample", "Notes field sample text string"),
828  CELL_ALIGN_LEFT,
829  FALSE,
830  TRUE);
831 
832  gnc_register_add_cell (layout,
833  VNOTES_CELL,
834  BASIC_CELL_TYPE_NAME,
835  C_ ("sample", "No Particular Reason"),
836  CELL_ALIGN_RIGHT,
837  FALSE,
838  TRUE);
839 
840  gnc_register_add_cell (layout,
841  FCRED_CELL,
842  FORMULA_CELL_TYPE_NAME,
843  C_ ("sample", "(x + 0.33 * y + (x+y) )"),
844  CELL_ALIGN_LEFT,
845  FALSE,
846  FALSE);
847 
848  gnc_register_add_cell (layout,
849  FDEBT_CELL,
850  FORMULA_CELL_TYPE_NAME,
851  C_ ("sample", "(x + 0.33 * y + (x+y) )"),
852  CELL_ALIGN_LEFT,
853  FALSE,
854  FALSE);
855 
856  gnc_register_add_cell (layout,
857  RBALN_CELL,
858  PRICE_CELL_TYPE_NAME,
859  C_ ("sample", "999,999.000"),
860  CELL_ALIGN_RIGHT,
861  FALSE,
862  FALSE);
863 
864 }
865 
866 TableLayout*
867 gnc_split_register_layout_new (SplitRegister* reg)
868 {
869  TableLayout* layout;
870 
871  layout = gnc_table_layout_new();
872 
873  gnc_split_register_layout_add_cells (reg, layout);
874  gnc_split_register_layout_add_cursors (reg, layout);
875  gnc_split_register_set_cells (reg, layout);
876 
877  return layout;
878 }
SplitRegisterTypeGroup gnc_split_register_get_register_group(SplitRegister *reg)
Group registers for common layouts.
Create the actual register visual layout.
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244
TableLayout * gnc_table_layout_new(void)
API Declarations.
Definition: table-layout.c:59
#define CURSOR_HEADER
Standard Cursor Names.
Definition: table-layout.h:36
All type declarations for the whole Gnucash engine.
TableLayout * gnc_split_register_layout_new(SplitRegister *reg)
Generate the split register layout.
CellBlock * gnc_cellblock_new(int rows, int cols, const char *cursor_name)
Create a new CellBlock on the heap.
Definition: cellblock.c:44
BasicCell * gnc_cellblock_get_cell(CellBlock *cellblock, int row, int col)
Retrieve the Cell at the specified coordinates.
Definition: cellblock.c:109