GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gncEntryLedgerLayout.c
1 /*
2  * gncEntryLedgerLayout.c -- Layout for GncEntry ledger
3  * Copyright (C) 2001, 2002, 2003 Derek Atkins
4  * Author: Derek Atkins <[email protected]>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, contact:
18  *
19  * Free Software Foundation Voice: +1-617-542-5942
20  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
21  * Boston, MA 02110-1301, USA [email protected]
22  */
23 
24 #include "config.h"
25 
26 #include <glib.h>
27 #include <glib/gi18n.h>
28 
29 #include "gncEntryLedgerP.h"
30 #include "gncEntryLedgerLayout.h"
31 
32 static void
33 gnc_register_add_cell (TableLayout *layout,
34  const char *cell_name,
35  const char *cell_type_name,
36  const char *sample_text,
37  CellAlignment alignment,
38  gboolean expandable,
39  gboolean span)
40 {
41  BasicCell *cell;
42 
43  g_return_if_fail (layout != NULL);
44  g_return_if_fail (cell_type_name != NULL);
45 
46  cell = gnc_register_make_cell (cell_type_name);
47 
48  gnc_basic_cell_set_name (cell, cell_name);
49  gnc_basic_cell_set_type_name (cell, cell_type_name);
50  gnc_basic_cell_set_sample_text (cell, sample_text);
51  gnc_basic_cell_set_alignment (cell, alignment);
52  gnc_basic_cell_set_expandable (cell, expandable);
53  gnc_basic_cell_set_span (cell, span);
54 
55  gnc_table_layout_add_cell (layout, cell);
56 }
57 
58 static void gnc_entry_ledger_layout_add_cells (GncEntryLedger *ledger,
59  TableLayout *layout)
60 {
61  struct cell_list
62  {
63  const char *cell_name;
64  const char *cell_type_name;
65  const char *sample_text;
66  CellAlignment alignment;
67  gboolean expandable;
68  gboolean span;
69  } cells[] =
70  {
71  /* Translators: The 'sample:' items are strings which are not
72  displayed, but only used to estimate widths. Please only
73  translate the portion after the ':' and leave the rest
74  ("sample:") as is. */
75  {
76  ENTRY_INV_CELL, CHECKBOX_CELL_TYPE_NAME, N_("sample:X") + 7,
77  CELL_ALIGN_LEFT, FALSE, FALSE
78  },
79  {
80  ENTRY_DATE_CELL, DATE_CELL_TYPE_NAME, N_("sample:12/12/2000") + 7,
81  CELL_ALIGN_RIGHT, FALSE, FALSE
82  },
83  {
84  ENTRY_DESC_CELL, QUICKFILL_CELL_TYPE_NAME,
85  N_("sample:Description of an Entry") + 7, CELL_ALIGN_LEFT, TRUE, FALSE
86  },
87  {
88  ENTRY_ACTN_CELL, COMBO_CELL_TYPE_NAME,
89  N_("sample:Action") + 7, CELL_ALIGN_RIGHT,
90  FALSE, FALSE
91  },
92  {
93  ENTRY_QTY_CELL, PRICE_CELL_TYPE_NAME, N_("sample:9,999.00") + 7,
94  CELL_ALIGN_RIGHT, FALSE, FALSE
95  },
96  {
97  ENTRY_PRIC_CELL, PRICE_CELL_TYPE_NAME, N_("sample:999,999.00") + 7,
98  CELL_ALIGN_RIGHT, FALSE, FALSE
99  },
100  {
101  ENTRY_DISC_CELL, PRICE_CELL_TYPE_NAME, N_("sample:9,999.00") + 7,
102  CELL_ALIGN_RIGHT, FALSE, FALSE
103  },
104  /* xgettext:no-c-format */
105  {
106  ENTRY_DISTYPE_CELL, RECN_CELL_TYPE_NAME, N_("sample(DT):+%") + 11,
107  CELL_ALIGN_LEFT, FALSE, FALSE
108  },
109  /* xgettext:no-c-format */
110  {
111  ENTRY_DISHOW_CELL, RECN_CELL_TYPE_NAME, N_("sample(DH):+%") + 11,
112  CELL_ALIGN_LEFT, FALSE, FALSE
113  },
114  {
115  ENTRY_IACCT_CELL, COMBO_CELL_TYPE_NAME,
116  N_("sample:Expenses:Automobile:Gasoline") + 7,
117  CELL_ALIGN_RIGHT, FALSE, FALSE
118  },
119  {
120  ENTRY_BACCT_CELL, COMBO_CELL_TYPE_NAME,
121  N_("sample:Expenses:Automobile:Gasoline") + 7,
122  CELL_ALIGN_RIGHT, FALSE, FALSE
123  },
124  {
125  ENTRY_TAXABLE_CELL, CHECKBOX_CELL_TYPE_NAME, N_("sample:T?") + 7,
126  CELL_ALIGN_LEFT, FALSE, FALSE
127  },
128  {
129  ENTRY_TAXINCLUDED_CELL, CHECKBOX_CELL_TYPE_NAME, N_("sample:TI") + 7,
130  CELL_ALIGN_LEFT, FALSE, FALSE
131  },
132  {
133  ENTRY_TAXTABLE_CELL, COMBO_CELL_TYPE_NAME, N_("sample:Tax Table 1") + 7,
134  CELL_ALIGN_RIGHT, FALSE, FALSE
135  },
136  {
137  ENTRY_VALUE_CELL, PRICE_CELL_TYPE_NAME, N_("sample:999,999.00") + 7,
138  CELL_ALIGN_RIGHT, FALSE, FALSE
139  },
140  {
141  ENTRY_TAXVAL_CELL, PRICE_CELL_TYPE_NAME, N_("sample:999.00") + 7,
142  CELL_ALIGN_RIGHT, FALSE, FALSE
143  },
144  {
145  ENTRY_BILLABLE_CELL, CHECKBOX_CELL_TYPE_NAME, N_("sample:BI") + 7,
146  CELL_ALIGN_LEFT, FALSE, FALSE
147  },
148  {
149  ENTRY_PAYMENT_CELL, COMBO_CELL_TYPE_NAME, N_("sample:Payment") + 7,
150  CELL_ALIGN_LEFT, FALSE, FALSE
151  }
152  };
153  unsigned int i;
154 
155  for (i = 0; i < (sizeof(cells) / sizeof(*cells)); i++)
156  gnc_register_add_cell (layout, cells[i].cell_name, cells[i].cell_type_name,
157  cells[i].sample_text, cells[i].alignment,
158  cells[i].expandable, cells[i].span);
159 }
160 
161 static void gnc_entry_ledger_layout_add_cursors (GncEntryLedger *ledger,
162  TableLayout *layout)
163 {
164  CellBlock *cursor;
165  int num_cols;
166 
167  switch (ledger->type)
168  {
169  case GNCENTRY_ORDER_ENTRY:
170  case GNCENTRY_ORDER_VIEWER:
171  case GNCENTRY_INVOICE_ENTRY:
172  case GNCENTRY_INVOICE_VIEWER:
173  case GNCENTRY_CUST_CREDIT_NOTE_ENTRY:
174  case GNCENTRY_CUST_CREDIT_NOTE_VIEWER:
175  num_cols = 15;
176  break;
177  case GNCENTRY_BILL_ENTRY:
178  case GNCENTRY_BILL_VIEWER:
179  case GNCENTRY_VEND_CREDIT_NOTE_ENTRY:
180  case GNCENTRY_VEND_CREDIT_NOTE_VIEWER:
181  num_cols = 12;
182  break;
183  case GNCENTRY_EXPVOUCHER_ENTRY:
184  case GNCENTRY_EXPVOUCHER_VIEWER:
185  case GNCENTRY_EMPL_CREDIT_NOTE_ENTRY:
186  case GNCENTRY_EMPL_CREDIT_NOTE_VIEWER:
187  num_cols = 10;
188  break;
189  default:
190  g_assert (FALSE);
191  return;
192  }
193 
194  cursor = gnc_cellblock_new (1, num_cols, CURSOR_HEADER);
195  gnc_table_layout_add_cursor (layout, cursor);
196 
197  cursor = gnc_cellblock_new (1, num_cols, "cursor");
198  gnc_table_layout_add_cursor (layout, cursor);
199  gnc_table_layout_set_primary_cursor (layout, cursor);
200 }
201 
202 static void gnc_entry_ledger_set_cells (GncEntryLedger *ledger,
203  TableLayout *layout)
204 {
205  CellBlock *curs;
206 
207  switch (ledger->type)
208  {
209  case GNCENTRY_ORDER_ENTRY:
210  case GNCENTRY_ORDER_VIEWER:
211  case GNCENTRY_INVOICE_ENTRY:
212  case GNCENTRY_INVOICE_VIEWER:
213  case GNCENTRY_CUST_CREDIT_NOTE_ENTRY:
214  case GNCENTRY_CUST_CREDIT_NOTE_VIEWER:
215 
216  curs = gnc_table_layout_get_cursor (layout, "cursor");
217  gnc_table_layout_set_cell (layout, curs, ENTRY_DATE_CELL, 0, 0);
218  gnc_table_layout_set_cell (layout, curs, ENTRY_INV_CELL, 0, 1);
219  gnc_table_layout_set_cell (layout, curs, ENTRY_DESC_CELL, 0, 2);
220  gnc_table_layout_set_cell (layout, curs, ENTRY_ACTN_CELL, 0, 3);
221  gnc_table_layout_set_cell (layout, curs, ENTRY_IACCT_CELL, 0, 4);
222  gnc_table_layout_set_cell (layout, curs, ENTRY_QTY_CELL, 0, 5);
223  gnc_table_layout_set_cell (layout, curs, ENTRY_PRIC_CELL, 0, 6);
224  gnc_table_layout_set_cell (layout, curs, ENTRY_DISTYPE_CELL, 0, 7);
225  gnc_table_layout_set_cell (layout, curs, ENTRY_DISHOW_CELL, 0, 8);
226  gnc_table_layout_set_cell (layout, curs, ENTRY_DISC_CELL, 0, 9);
227  gnc_table_layout_set_cell (layout, curs, ENTRY_TAXABLE_CELL, 0, 10);
228  gnc_table_layout_set_cell (layout, curs, ENTRY_TAXINCLUDED_CELL, 0, 11);
229  gnc_table_layout_set_cell (layout, curs, ENTRY_TAXTABLE_CELL, 0, 12);
230  gnc_table_layout_set_cell (layout, curs, ENTRY_VALUE_CELL, 0, 13);
231  gnc_table_layout_set_cell (layout, curs, ENTRY_TAXVAL_CELL, 0, 14);
232 
233  break;
234 
235  case GNCENTRY_BILL_ENTRY:
236  case GNCENTRY_BILL_VIEWER:
237  case GNCENTRY_VEND_CREDIT_NOTE_ENTRY:
238  case GNCENTRY_VEND_CREDIT_NOTE_VIEWER:
239 
240  curs = gnc_table_layout_get_cursor (layout, "cursor");
241  gnc_table_layout_set_cell (layout, curs, ENTRY_DATE_CELL, 0, 0);
242  gnc_table_layout_set_cell (layout, curs, ENTRY_INV_CELL, 0, 1);
243  gnc_table_layout_set_cell (layout, curs, ENTRY_DESC_CELL, 0, 2);
244  gnc_table_layout_set_cell (layout, curs, ENTRY_ACTN_CELL, 0, 3);
245  gnc_table_layout_set_cell (layout, curs, ENTRY_BACCT_CELL, 0, 4);
246  gnc_table_layout_set_cell (layout, curs, ENTRY_QTY_CELL, 0, 5);
247  gnc_table_layout_set_cell (layout, curs, ENTRY_PRIC_CELL, 0, 6);
248  gnc_table_layout_set_cell (layout, curs, ENTRY_TAXABLE_CELL, 0, 7);
249  gnc_table_layout_set_cell (layout, curs, ENTRY_TAXINCLUDED_CELL, 0, 8);
250  gnc_table_layout_set_cell (layout, curs, ENTRY_TAXTABLE_CELL, 0, 9);
251  gnc_table_layout_set_cell (layout, curs, ENTRY_VALUE_CELL, 0, 10);
252  gnc_table_layout_set_cell (layout, curs, ENTRY_BILLABLE_CELL, 0, 11);
253 
254  break;
255 
256  case GNCENTRY_EXPVOUCHER_ENTRY:
257  case GNCENTRY_EXPVOUCHER_VIEWER:
258  case GNCENTRY_EMPL_CREDIT_NOTE_ENTRY:
259  case GNCENTRY_EMPL_CREDIT_NOTE_VIEWER:
260 
261  curs = gnc_table_layout_get_cursor (layout, "cursor");
262  gnc_table_layout_set_cell (layout, curs, ENTRY_DATE_CELL, 0, 0);
263  gnc_table_layout_set_cell (layout, curs, ENTRY_INV_CELL, 0, 1);
264  gnc_table_layout_set_cell (layout, curs, ENTRY_DESC_CELL, 0, 2);
265  gnc_table_layout_set_cell (layout, curs, ENTRY_ACTN_CELL, 0, 3);
266  gnc_table_layout_set_cell (layout, curs, ENTRY_BACCT_CELL, 0, 4);
267  gnc_table_layout_set_cell (layout, curs, ENTRY_QTY_CELL, 0, 5);
268  gnc_table_layout_set_cell (layout, curs, ENTRY_PRIC_CELL, 0, 6);
269  gnc_table_layout_set_cell (layout, curs, ENTRY_VALUE_CELL, 0, 7);
270  gnc_table_layout_set_cell (layout, curs, ENTRY_BILLABLE_CELL, 0, 8);
271  gnc_table_layout_set_cell (layout, curs, ENTRY_PAYMENT_CELL, 0, 9);
272 
273  break;
274 
275  default:
276  g_assert (FALSE);
277  return;
278  }
279 }
280 
281 TableLayout * gnc_entry_ledger_layout_new (GncEntryLedger *ledger)
282 {
283  TableLayout *layout;
284 
285  layout = gnc_table_layout_new ();
286  gnc_entry_ledger_layout_add_cells (ledger, layout);
287  gnc_entry_ledger_layout_add_cursors (ledger, layout);
288  gnc_entry_ledger_set_cells (ledger, layout);
289 
290  return layout;
291 }
292 
293