GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 [email protected] *
20  * *
21 \********************************************************************/
22 
23 /* quickfillcell-gnome.c
24  *
25  * Implements gnome dependent quickfill cell functions.
26  *
27  * Copyright (C) 2000 Dave Peticolas <[email protected]>
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 
38 
39 static gboolean
40 gnc_quickfill_cell_direct_update (BasicCell *bcell,
41  int *cursor_position,
42  int *start_selection,
43  int *end_selection,
44  void *gui_data)
45 {
46  QuickFillCell *cell = (QuickFillCell *) bcell;
47  GdkEventKey *event = gui_data;
48  const char *match_str;
49  QuickFill *match;
50  int prefix_len;
51 
52  if (event->type != GDK_KEY_PRESS)
53  return FALSE;
54 
55  switch (event->keyval)
56  {
57  case GDK_KEY_slash:
58  if (!(event->state & GDK_MOD1_MASK))
59  return FALSE;
60  break;
61  case GDK_KEY_Tab:
62  case GDK_KEY_ISO_Left_Tab:
63  if (!(event->state & GDK_CONTROL_MASK))
64  return FALSE;
65  break;
66  default:
67  return FALSE;
68  }
69 
70  if ((*start_selection <= *cursor_position) &&
71  (*end_selection >= *cursor_position))
72  *cursor_position = *start_selection;
73  else if ((*end_selection <= *cursor_position) &&
74  (*start_selection >= *cursor_position))
75  *cursor_position = *end_selection;
76 
77  match = gnc_quickfill_get_string_len_match (cell->qf, bcell->value,
78  *cursor_position);
79 
80  if (match == NULL)
81  return TRUE;
82 
83  match = gnc_quickfill_get_unique_len_match (match, &prefix_len);
84  if (match == NULL)
85  return TRUE;
86 
87  match_str = gnc_quickfill_string (match);
88 
89  if ((match_str != NULL) &&
90  (strncmp (match_str, bcell->value, strlen (bcell->value)) == 0) &&
91  (strcmp (match_str, bcell->value) != 0))
92  gnc_basic_cell_set_value (bcell, match_str);
93 
94  *cursor_position += prefix_len;
95  *start_selection = *cursor_position;
96  *end_selection = -1;
97 
98  return TRUE;
99 }
100 
101 BasicCell *
102 gnc_quickfill_cell_gnome_new (void)
103 {
104  BasicCell *cell;
105 
106  cell = gnc_quickfill_cell_new ();
107 
108  cell->direct_update = gnc_quickfill_cell_direct_update;
109 
110  return cell;
111 }
112 
QuickFill * gnc_quickfill_get_string_len_match(QuickFill *qf, const char *str, int len)
Definition: QuickFill.c:150
const char * gnc_quickfill_string(QuickFill *qf)
Definition: QuickFill.c:123
QuickFill * gnc_quickfill_get_unique_len_match(QuickFill *qf, int *length)
Definition: QuickFill.c:199