GnuCash  5.6-150-g038405b370+
formulacell-gnome.c
1 /********************************************************************\
2  * This program is free software; you can redistribute it and/or *
3  * modify it under the terms of the GNU General Public License as *
4  * published by the Free Software Foundation; either version 2 of *
5  * the License, or (at your option) any later version. *
6  * *
7  * This program is distributed in the hope that it will be useful, *
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
10  * GNU General Public License for more details. *
11  * *
12  * You should have received a copy of the GNU General Public License*
13  * along with this program; if not, contact: *
14  * *
15  * Free Software Foundation Voice: +1-617-542-5942 *
16  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
17  * Boston, MA 02110-1301, USA gnu@gnu.org *
18  * *
19 \********************************************************************/
20 
21 /* formulacell-gnome.c
22  *
23  * Implements Gnome-dependent formula-cell functions :
24  *
25  * Often the decimal key in the keypad is not mapped to the correct locale
26  * decimal point, the function PriceDirect handle this case.
27  */
28 
29 #include <config.h>
30 
31 #include <locale.h>
32 #include <gdk/gdkkeysyms.h>
33 
34 #include "gnc-engine.h"
35 
36 #include "gnc-locale-utils.h"
37 #include "gnc-ui-util.h"
38 
39 #include "formulacell.h"
40 #include "formulacell-gnome.h"
41 #include "pricecell-gnome.h"
42 
43 #ifdef G_OS_WIN32
44 # include <gdk/gdkwin32.h>
45 #endif
46 
47 //static QofLogModule log_module = GNC_MOD_REGISTER;
48 
49 static
50 gboolean
51 gnc_formula_cell_direct_update( BasicCell *bcell,
52  int *cursor_position,
53  int *start_selection,
54  int *end_selection,
55  void *gui_data )
56 {
57  FormulaCell *cell = (FormulaCell *)bcell;
58  GdkEventKey *event = gui_data;
59  struct lconv *lc;
60  gboolean is_return;
61 
62  if (event->type != GDK_KEY_PRESS)
63  return FALSE;
64 
65  lc = gnc_localeconv ();
66 
67  is_return = FALSE;
68 
69  /* FIXME!! This code is almost identical (except for GDK_KEY_KP_Enter
70  * handling) to pricecell-gnome.c:gnc_price_cell_direct_update. I write
71  * this after fixing a bug where one copy was kept up to date, and the
72  * other not. So, fix this.
73  */
74 
75  switch (event->keyval)
76  {
77  case GDK_KEY_Return:
78  if (!(event->state &
79  (GDK_MODIFIER_INTENT_DEFAULT_MOD_MASK)))
80  is_return = TRUE;
81  /* FALL THROUGH */
82 
83  case GDK_KEY_KP_Enter:
84  {
85  gnc_formula_cell_set_value( cell, cell->cell.value );
86 
87  /* If it's not a plain return, stay put. This
88  * allows a 'calculator' style operation using
89  * keypad enter where you can keep entering more
90  * items to add, say. */
91  return !is_return;
92  }
93 
94  case GDK_KEY_KP_Decimal:
95  break;
96 
97  default:
98  return FALSE;
99  }
100 
101  gnc_basic_cell_insert_decimal(bcell,
102  cell->print_info.monetary
103  ? lc->mon_decimal_point[0]
104  : lc->decimal_point[0],
105  cursor_position,
106  start_selection,
107  end_selection);
108 
109  return TRUE;
110 }
111 
112 BasicCell *
113 gnc_formula_cell_gnome_new (void)
114 {
115  BasicCell *cell;
116 
117  cell = gnc_formula_cell_new ();
118  cell->direct_update = gnc_formula_cell_direct_update;
119  return cell;
120 }
Implements gnome dependent formula cell functions.
utility functions for the GnuCash UI
All type declarations for the whole Gnucash engine.
The FormulaCell is a register-table cell which can contain a formula involving numbers, formula markup and strings denoting either functions or variables.
Definition: formulacell.h:42
GNCPrintAmountInfo print_info
The print-info for numeric values.
Definition: formulacell.h:47