GnuCash c935c2f+
Loading...
Searching...
No Matches
quickfillcell-gnome.c
1/********************************************************************\
2 * quickfillcell-gnome.c -- implement gnome part of quickfill cell *
3 * *
4 * This program is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU General Public License as *
6 * published by the Free Software Foundation; either version 2 of *
7 * the License, or (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License*
15 * along with this program; if not, contact: *
16 * *
17 * Free Software Foundation Voice: +1-617-542-5942 *
18 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
19 * Boston, MA 02110-1301, USA gnu@gnu.org *
20 * *
21\********************************************************************/
22
23/* quickfillcell-gnome.c
24 *
25 * Implements gnome dependent quickfill cell functions.
26 *
27 * Copyright (C) 2000 Dave Peticolas <dave@krondo.com>
28 */
29
30#include <config.h>
31
32#include <string.h>
33#include <gdk/gdkkeysyms.h>
34
35#include "quickfillcell.h"
36#include "quickfillcell-gnome.h"
37#include "gnucash-sheet.h"
38#include "gnucash-sheetP.h"
39#include "table-allgui.h"
40
41
42static gboolean
43gnc_quickfill_cell_direct_update (BasicCell *bcell,
44 int *cursor_position,
45 int *start_selection,
46 int *end_selection,
47 void *gui_data)
48{
49 QuickFillCell *cell = (QuickFillCell *) bcell;
50 GdkEventKey *event = gui_data;
51 const char *match_str;
52 QuickFill *match;
53 int prefix_len;
54
55 if (event->type != GDK_KEY_PRESS)
56 return FALSE;
57
58 switch (event->keyval)
59 {
60 case GDK_KEY_Escape:
61 if (bcell->changed)
62 {
63 GnucashSheet *sheet = (GnucashSheet *) bcell->gui_private;
64 const char *value = gnc_table_get_model_entry (sheet->table, bcell->cell_name);
65
66 gnc_basic_cell_set_value_internal (bcell, value);
67 bcell->changed = FALSE;
68 *cursor_position = 0;
69 *start_selection = 0;
70 *end_selection = -1;
71 return TRUE;
72 }
73 return FALSE;
74 case GDK_KEY_slash:
75 if (!(event->state & GDK_MOD1_MASK))
76 return FALSE;
77 break;
78 case GDK_KEY_Tab:
79 case GDK_KEY_ISO_Left_Tab:
80 if (!(event->state & GDK_CONTROL_MASK))
81 return FALSE;
82 break;
83 default:
84 return FALSE;
85 }
86
87 if ((*start_selection <= *cursor_position) &&
88 (*end_selection >= *cursor_position))
89 *cursor_position = *start_selection;
90 else if ((*end_selection <= *cursor_position) &&
91 (*start_selection >= *cursor_position))
92 *cursor_position = *end_selection;
93
94 match = gnc_quickfill_get_string_len_match (cell->qf, bcell->value,
95 *cursor_position);
96
97 if (match == NULL)
98 return TRUE;
99
100 match = gnc_quickfill_get_unique_len_match (match, &prefix_len);
101 if (match == NULL)
102 return TRUE;
103
104 match_str = gnc_quickfill_string (match);
105
106 if ((match_str != NULL) &&
107 (strncmp (match_str, bcell->value, strlen (bcell->value)) == 0) &&
108 (strcmp (match_str, bcell->value) != 0))
109 gnc_basic_cell_set_value (bcell, match_str);
110
111 *cursor_position += prefix_len;
112 *start_selection = *cursor_position;
113 *end_selection = -1;
114
115 return TRUE;
116}
117
118BasicCell *
119gnc_quickfill_cell_gnome_new (void)
120{
121 BasicCell *cell;
122
123 cell = gnc_quickfill_cell_new ();
124
125 cell->direct_update = gnc_quickfill_cell_direct_update;
126
127 return cell;
128}
129
Private declarations for GnucashSheet class.
Public declarations of GnucashRegister class.
const char * gnc_quickfill_string(QuickFill *qf)
For the given node 'qf', return the best-guess matching string.
Definition QuickFill.c:123
QuickFill * gnc_quickfill_get_string_len_match(QuickFill *qf, const char *str, int len)
Same as gnc_quickfill_get_string_match(), except that the string length is explicitly specified.
Definition QuickFill.c:150
QuickFill * gnc_quickfill_get_unique_len_match(QuickFill *qf, int *length)
Walk a 'unique' part of the QuickFill tree.
Definition QuickFill.c:199
The QuickFillCell implements a text cell with quick-fill capabilities.
Declarations for the Table object.