GnuCash c935c2f+
Loading...
Searching...
No Matches
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#include "gnucash-sheet.h"
43#include "gnucash-sheetP.h"
44#include "table-allgui.h"
45
46#ifdef G_OS_WIN32
47# include <gdk/gdkwin32.h>
48#endif
49
50//static QofLogModule log_module = GNC_MOD_REGISTER;
51
52static
53gboolean
54gnc_formula_cell_direct_update( BasicCell *bcell,
55 int *cursor_position,
56 int *start_selection,
57 int *end_selection,
58 void *gui_data )
59{
60 FormulaCell *cell = (FormulaCell *)bcell;
61 GdkEventKey *event = gui_data;
62 struct lconv *lc;
63 gboolean is_return;
64
65 if (event->type != GDK_KEY_PRESS)
66 return FALSE;
67
68 lc = gnc_localeconv ();
69
70 is_return = FALSE;
71
72 /* FIXME!! This code is almost identical (except for GDK_KEY_KP_Enter
73 * handling) to pricecell-gnome.c:gnc_price_cell_direct_update. I write
74 * this after fixing a bug where one copy was kept up to date, and the
75 * other not. So, fix this.
76 */
77
78 switch (event->keyval)
79 {
80 case GDK_KEY_Escape:
81 if (bcell->changed)
82 {
83 GnucashSheet *sheet = (GnucashSheet *) bcell->gui_private;
84 const char *value = gnc_table_get_model_entry (sheet->table, bcell->cell_name);
85
86 gnc_basic_cell_set_value_internal (bcell, value);
87 bcell->changed = FALSE;
88 *cursor_position = 0;
89 *start_selection = 0;
90 *end_selection = -1;
91 return TRUE;
92 }
93 return FALSE;
94
95 case GDK_KEY_Return:
96 if (!(event->state &
97 (GDK_MODIFIER_INTENT_DEFAULT_MOD_MASK)))
98 is_return = TRUE;
99 /* FALL THROUGH */
100
101 case GDK_KEY_KP_Enter:
102 {
103 gnc_formula_cell_set_value( cell, cell->cell.value );
104
105 /* If it's not a plain return, stay put. This
106 * allows a 'calculator' style operation using
107 * keypad enter where you can keep entering more
108 * items to add, say. */
109 return !is_return;
110 }
111
112 case GDK_KEY_KP_Decimal:
113 break;
114
115 default:
116 return FALSE;
117 }
118
119 gnc_basic_cell_insert_decimal(bcell,
120 cell->print_info.monetary
121 ? lc->mon_decimal_point[0]
122 : lc->decimal_point[0],
123 cursor_position,
124 start_selection,
125 end_selection);
126
127 return TRUE;
128}
129
130BasicCell *
131gnc_formula_cell_gnome_new (void)
132{
133 BasicCell *cell;
134
135 cell = gnc_formula_cell_new ();
136 cell->direct_update = gnc_formula_cell_direct_update;
137 return cell;
138}
Implements gnome dependent formula cell functions.
All type declarations for the whole Gnucash engine.
utility functions for the GnuCash UI
Private declarations for GnucashSheet class.
Public declarations of GnucashRegister class.
The FormulaCell is a register-table cell which can contain a formula involving numbers,...
Definition formulacell.h:43
GNCPrintAmountInfo print_info
The print-info for numeric values.
Definition formulacell.h:47
Declarations for the Table object.