GnuCash  5.6-150-g038405b370+
gncEntryLedgerLayout.c
1 /*
2  * gncEntryLedgerLayout.c -- Layout for GncEntry ledger
3  * Copyright (C) 2001, 2002, 2003 Derek Atkins
4  * Author: Derek Atkins <warlord@MIT.EDU>
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 gnu@gnu.org
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 following strings are used for the layout of the
72  cells while editing invoices.
73  Important: The 'sample:' items are strings which are not
74  displayed, but only used to estimate widths.
75  This sample is for a checkbox */
76  {
77  ENTRY_INV_CELL, CHECKBOX_CELL_TYPE_NAME, C_("sample for a checkbox", "X"),
78  CELL_ALIGN_LEFT, FALSE, FALSE
79  },
80  {
81  ENTRY_DATE_CELL, DATE_CELL_TYPE_NAME, C_("sample for 'Date'", "12/12/2000"),
82  CELL_ALIGN_RIGHT, FALSE, FALSE
83  },
84  {
85  ENTRY_DESC_CELL, QUICKFILL_CELL_TYPE_NAME,
86  C_("sample for 'Description'", "Description of an Entry"), CELL_ALIGN_LEFT,
87  TRUE, FALSE
88  },
89  {
90  /* Translators: Enter the longest 'Action' entry */
91  ENTRY_ACTN_CELL, COMBO_CELL_TYPE_NAME,
92  C_("sample", "Action"), CELL_ALIGN_RIGHT,
93  FALSE, FALSE
94  },
95  {
96  ENTRY_QTY_CELL, PRICE_CELL_TYPE_NAME, C_("sample", "9,999.00"),
97  CELL_ALIGN_RIGHT, FALSE, FALSE
98  },
99  {
100  ENTRY_PRIC_CELL, PRICE_CELL_TYPE_NAME, C_("sample", "999,999.00"),
101  CELL_ALIGN_RIGHT, FALSE, FALSE
102  },
103  {
104  ENTRY_DISC_CELL, PRICE_CELL_TYPE_NAME, C_("sample", "9,999.00"),
105  CELL_ALIGN_RIGHT, FALSE, FALSE
106  },
107  {
108  /* xgettext:no-c-format
109  Translators: Header for Discount Type */
110  ENTRY_DISTYPE_CELL, RECN_CELL_TYPE_NAME, C_("sample for 'Discount Type'", "+%"),
111  CELL_ALIGN_LEFT, FALSE, FALSE
112  },
113  {
114  /* xgettext:no-c-format
115  Translators: Header for Discount How */
116  ENTRY_DISHOW_CELL, RECN_CELL_TYPE_NAME, C_("sample for Discount How'", "+%"),
117  CELL_ALIGN_LEFT, FALSE, FALSE
118  },
119  {
120  ENTRY_IACCT_CELL, COMBO_CELL_TYPE_NAME,
121  /* Translators: Enter the longest expected path of an Account */
122  C_("sample", "Expenses:Automobile:Gasoline"),
123  CELL_ALIGN_RIGHT, FALSE, FALSE
124  },
125  {
126  ENTRY_BACCT_CELL, COMBO_CELL_TYPE_NAME,
127  C_("sample", "Expenses:Automobile:Gasoline"),
128  CELL_ALIGN_RIGHT, FALSE, FALSE
129  },
130  {
131  /* Translators: Abbreviation sample for Taxable? */
132  ENTRY_TAXABLE_CELL, CHECKBOX_CELL_TYPE_NAME, C_("sample for 'Taxable'", "T?"),
133  CELL_ALIGN_LEFT, FALSE, FALSE
134  },
135  {
136  /* Translators: Abbreviation sample for Tax Included */
137  ENTRY_TAXINCLUDED_CELL, CHECKBOX_CELL_TYPE_NAME, C_("sample for 'Tax Included'", "TI"),
138  CELL_ALIGN_LEFT, FALSE, FALSE
139  },
140  {
141  ENTRY_TAXTABLE_CELL, COMBO_CELL_TYPE_NAME, C_("sample for 'Tax Table'", "Tax Table 1"),
142  CELL_ALIGN_RIGHT, FALSE, FALSE
143  },
144  {
145  ENTRY_VALUE_CELL, PRICE_CELL_TYPE_NAME, C_("sample", "999,999.00"),
146  CELL_ALIGN_RIGHT, FALSE, FALSE
147  },
148  {
149  ENTRY_TAXVAL_CELL, PRICE_CELL_TYPE_NAME, C_("sample", "999.00"),
150  CELL_ALIGN_RIGHT, FALSE, FALSE
151  },
152  {
153  /* Translators: Abbreviation sample for Billable */
154  ENTRY_BILLABLE_CELL, CHECKBOX_CELL_TYPE_NAME, C_("sample for 'Billable'", "BI"),
155  CELL_ALIGN_LEFT, FALSE, FALSE
156  },
157  {
158  ENTRY_PAYMENT_CELL, COMBO_CELL_TYPE_NAME, C_("sample", "Payment"),
159  CELL_ALIGN_LEFT, FALSE, FALSE
160  }
161  };
162  unsigned int i;
163 
164  for (i = 0; i < (sizeof(cells) / sizeof(*cells)); i++)
165  gnc_register_add_cell (layout, cells[i].cell_name, cells[i].cell_type_name,
166  cells[i].sample_text, cells[i].alignment,
167  cells[i].expandable, cells[i].span);
168 }
169 
170 static void gnc_entry_ledger_layout_add_cursors (GncEntryLedger *ledger,
171  TableLayout *layout)
172 {
173  CellBlock *cursor;
174  int num_cols;
175 
176  switch (ledger->type)
177  {
178  case GNCENTRY_ORDER_ENTRY:
179  case GNCENTRY_ORDER_VIEWER:
180  case GNCENTRY_INVOICE_ENTRY:
181  case GNCENTRY_INVOICE_VIEWER:
182  case GNCENTRY_CUST_CREDIT_NOTE_ENTRY:
183  case GNCENTRY_CUST_CREDIT_NOTE_VIEWER:
184  num_cols = 15;
185  break;
186  case GNCENTRY_BILL_ENTRY:
187  case GNCENTRY_BILL_VIEWER:
188  case GNCENTRY_VEND_CREDIT_NOTE_ENTRY:
189  case GNCENTRY_VEND_CREDIT_NOTE_VIEWER:
190  num_cols = 12;
191  break;
192  case GNCENTRY_EXPVOUCHER_ENTRY:
193  case GNCENTRY_EXPVOUCHER_VIEWER:
194  case GNCENTRY_EMPL_CREDIT_NOTE_ENTRY:
195  case GNCENTRY_EMPL_CREDIT_NOTE_VIEWER:
196  num_cols = 10;
197  break;
198  default:
199  g_assert (FALSE);
200  return;
201  }
202 
203  cursor = gnc_cellblock_new (1, num_cols, CURSOR_HEADER);
204  gnc_table_layout_add_cursor (layout, cursor);
205 
206  cursor = gnc_cellblock_new (1, num_cols, "cursor");
207  gnc_table_layout_add_cursor (layout, cursor);
208  gnc_table_layout_set_primary_cursor (layout, cursor);
209 }
210 
211 static void gnc_entry_ledger_set_cells (GncEntryLedger *ledger,
212  TableLayout *layout)
213 {
214  CellBlock *curs;
215 
216  switch (ledger->type)
217  {
218  case GNCENTRY_ORDER_ENTRY:
219  case GNCENTRY_ORDER_VIEWER:
220  case GNCENTRY_INVOICE_ENTRY:
221  case GNCENTRY_INVOICE_VIEWER:
222  case GNCENTRY_CUST_CREDIT_NOTE_ENTRY:
223  case GNCENTRY_CUST_CREDIT_NOTE_VIEWER:
224 
225  curs = gnc_table_layout_get_cursor (layout, "cursor");
226  gnc_table_layout_set_cell (layout, curs, ENTRY_DATE_CELL, 0, 0);
227  gnc_table_layout_set_cell (layout, curs, ENTRY_INV_CELL, 0, 1);
228  gnc_table_layout_set_cell (layout, curs, ENTRY_DESC_CELL, 0, 2);
229  gnc_table_layout_set_cell (layout, curs, ENTRY_ACTN_CELL, 0, 3);
230  gnc_table_layout_set_cell (layout, curs, ENTRY_IACCT_CELL, 0, 4);
231  gnc_table_layout_set_cell (layout, curs, ENTRY_QTY_CELL, 0, 5);
232  gnc_table_layout_set_cell (layout, curs, ENTRY_PRIC_CELL, 0, 6);
233  gnc_table_layout_set_cell (layout, curs, ENTRY_DISTYPE_CELL, 0, 7);
234  gnc_table_layout_set_cell (layout, curs, ENTRY_DISHOW_CELL, 0, 8);
235  gnc_table_layout_set_cell (layout, curs, ENTRY_DISC_CELL, 0, 9);
236  gnc_table_layout_set_cell (layout, curs, ENTRY_TAXABLE_CELL, 0, 10);
237  gnc_table_layout_set_cell (layout, curs, ENTRY_TAXINCLUDED_CELL, 0, 11);
238  gnc_table_layout_set_cell (layout, curs, ENTRY_TAXTABLE_CELL, 0, 12);
239  gnc_table_layout_set_cell (layout, curs, ENTRY_VALUE_CELL, 0, 13);
240  gnc_table_layout_set_cell (layout, curs, ENTRY_TAXVAL_CELL, 0, 14);
241 
242  break;
243 
244  case GNCENTRY_BILL_ENTRY:
245  case GNCENTRY_BILL_VIEWER:
246  case GNCENTRY_VEND_CREDIT_NOTE_ENTRY:
247  case GNCENTRY_VEND_CREDIT_NOTE_VIEWER:
248 
249  curs = gnc_table_layout_get_cursor (layout, "cursor");
250  gnc_table_layout_set_cell (layout, curs, ENTRY_DATE_CELL, 0, 0);
251  gnc_table_layout_set_cell (layout, curs, ENTRY_INV_CELL, 0, 1);
252  gnc_table_layout_set_cell (layout, curs, ENTRY_DESC_CELL, 0, 2);
253  gnc_table_layout_set_cell (layout, curs, ENTRY_ACTN_CELL, 0, 3);
254  gnc_table_layout_set_cell (layout, curs, ENTRY_BACCT_CELL, 0, 4);
255  gnc_table_layout_set_cell (layout, curs, ENTRY_QTY_CELL, 0, 5);
256  gnc_table_layout_set_cell (layout, curs, ENTRY_PRIC_CELL, 0, 6);
257  gnc_table_layout_set_cell (layout, curs, ENTRY_TAXABLE_CELL, 0, 7);
258  gnc_table_layout_set_cell (layout, curs, ENTRY_TAXINCLUDED_CELL, 0, 8);
259  gnc_table_layout_set_cell (layout, curs, ENTRY_TAXTABLE_CELL, 0, 9);
260  gnc_table_layout_set_cell (layout, curs, ENTRY_VALUE_CELL, 0, 10);
261  gnc_table_layout_set_cell (layout, curs, ENTRY_BILLABLE_CELL, 0, 11);
262 
263  break;
264 
265  case GNCENTRY_EXPVOUCHER_ENTRY:
266  case GNCENTRY_EXPVOUCHER_VIEWER:
267  case GNCENTRY_EMPL_CREDIT_NOTE_ENTRY:
268  case GNCENTRY_EMPL_CREDIT_NOTE_VIEWER:
269 
270  curs = gnc_table_layout_get_cursor (layout, "cursor");
271  gnc_table_layout_set_cell (layout, curs, ENTRY_DATE_CELL, 0, 0);
272  gnc_table_layout_set_cell (layout, curs, ENTRY_INV_CELL, 0, 1);
273  gnc_table_layout_set_cell (layout, curs, ENTRY_DESC_CELL, 0, 2);
274  gnc_table_layout_set_cell (layout, curs, ENTRY_ACTN_CELL, 0, 3);
275  gnc_table_layout_set_cell (layout, curs, ENTRY_BACCT_CELL, 0, 4);
276  gnc_table_layout_set_cell (layout, curs, ENTRY_QTY_CELL, 0, 5);
277  gnc_table_layout_set_cell (layout, curs, ENTRY_PRIC_CELL, 0, 6);
278  gnc_table_layout_set_cell (layout, curs, ENTRY_VALUE_CELL, 0, 7);
279  gnc_table_layout_set_cell (layout, curs, ENTRY_BILLABLE_CELL, 0, 8);
280  gnc_table_layout_set_cell (layout, curs, ENTRY_PAYMENT_CELL, 0, 9);
281 
282  break;
283 
284  default:
285  g_assert (FALSE);
286  return;
287  }
288 }
289 
290 TableLayout * gnc_entry_ledger_layout_new (GncEntryLedger *ledger)
291 {
292  TableLayout *layout;
293 
294  layout = gnc_table_layout_new ();
295  gnc_entry_ledger_layout_add_cells (ledger, layout);
296  gnc_entry_ledger_layout_add_cursors (ledger, layout);
297  gnc_entry_ledger_set_cells (ledger, layout);
298 
299  return layout;
300 }
TableLayout * gnc_table_layout_new(void)
API Declarations.
Definition: table-layout.c:59
#define CURSOR_HEADER
Standard Cursor Names.
Definition: table-layout.h:36
CellBlock * gnc_cellblock_new(int rows, int cols, const char *cursor_name)
Create a new CellBlock on the heap.
Definition: cellblock.c:44