GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 [email protected] *
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_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 #ifdef G_OS_WIN32
75  /* gdk never sends GDK_KP_Decimal on win32. See #486658 */
76  if (event->hardware_keycode == VK_DECIMAL)
77  event->keyval = GDK_KP_Decimal;
78 #endif
79  switch (event->keyval)
80  {
81  case GDK_KEY_Return:
82  if (!(event->state &
83  (GDK_CONTROL_MASK | GDK_MOD1_MASK | GDK_SHIFT_MASK)))
84  is_return = TRUE;
85  /* FALL THROUGH */
86 
87  case GDK_KEY_KP_Enter:
88  {
89  gnc_formula_cell_set_value( cell, cell->cell.value );
90 
91  /* If it's not a plain return, stay put. This
92  * allows a 'calculator' style operation using
93  * keypad enter where you can keep entering more
94  * items to add, say. */
95  return !is_return;
96  }
97 
98  case GDK_KEY_KP_Decimal:
99  break;
100 
101  default:
102  return FALSE;
103  }
104 
105  gnc_basic_cell_insert_decimal(bcell,
106  cell->print_info.monetary
107  ? lc->mon_decimal_point[0]
108  : lc->decimal_point[0],
109  cursor_position,
110  start_selection,
111  end_selection);
112 
113  return TRUE;
114 }
115 
116 BasicCell *
117 gnc_formula_cell_gnome_new (void)
118 {
119  BasicCell *cell;
120 
121  cell = gnc_formula_cell_new ();
122  cell->direct_update = gnc_formula_cell_direct_update;
123  return cell;
124 }
utility functions for the GnuCash UI
GNCPrintAmountInfo print_info
Definition: formulacell.h:50
All type declarations for the whole Gnucash engine.